ise-uiuc / FreeFuzz

Free Lunch for Testing: Fuzzing Deep-Learning Libraries from Open Source (ICSE'22)
72 stars 14 forks source link

About GCOV #10

Open BiophiliaSWDA opened 10 months ago

BiophiliaSWDA commented 10 months ago

Hi, I am wondering how you relate GCOV to TensorFlow or Pytorch, because I am also currently experimenting with code coverage for deep learning networks, but I can't get operator coverage (or line coverage) for a TensorFlow network model after calling it from a C++ program.

I did this by calling the encapsulated network model from a C++ program and then using GCOV on the C++ program, but that didn't associate it with the source code.

#include <iostream>
#include "Python.h"

int main() {
    callModel();
    return 0;
}

// call python program
void callModel(){
    Py_Initialize();
    const char *init_call = "import sys\n"
                            "import os\n"
                            "sys.path.append('/'.join(os.getcwd().split('/')[:-1]))\n";
    PyRun_SimpleString(init_call);

    PyObject* pModule = PyImport_ImportModule("torch_.lenet");

    if (pModule != nullptr) {
        PyObject* pFunc = PyObject_GetAttrString(pModule, "go");
        PyObject_CallObject(pFunc, nullptr);
    }
    else{
        printf("Fail");
    }

    Py_Finalize();

}
g++ -fprofile-arcs -ftest-coverage main.cpp -o main
./main
gcov -n main.cpp
gcovr -v --html-details main.html    
Anjiang-Wei commented 10 months ago

For pytorch, there is a tool https://github.com/pytorch/pytorch/tree/main/tools/code_coverage For tensorflow, just try bazel https://github.com/tensorflow/tensorflow/issues/51091

Zoeeeeey commented 6 months ago

Hi, I have encountered a similar issue. How obtain the line coverage of the C/C++ code called by TensorFlow when running a Python test script? It seems that there is no mature solution in the link provided.

I have tried using Bazel to build the Python project, but there are many issues with importing TensorFlow. Do I need to compile TensorFlow locally using Bazel, or can it be imported as a third-party library?

I'm looking forward to your reply, any hint would be greatly helpful to me, thank you!! :-*) @Anjiang-Wei @BiophiliaSWDA

Anjiang-Wei commented 5 months ago

I remember there was a version compatibility issue with Bazel and GCOV. I forgot the details. @YangChenyuan may tell you more.