1

I find the link which shows how to run the unit tests.

And I think it could get a better understanding about the source code by debug the unit tests.

I can debug the source code as the tensorflow python application run. But I don't know how to debug the unit test. I am new to bazel and gdb debug.

Community
  • 1
  • 1
DunkOnly
  • 1,682
  • 4
  • 17
  • 39
  • 3
    Each "bazel test" essentially runs a corresponding binary under `bazel-bin` so you can run that binary directly, under gdb – Yaroslav Bulatov Oct 13 '16 at 18:00
  • @YaroslavBulatov Thank you , but I can't find the position of the test file . For example , common_shape_fns_test.cc , I search the `common_shape_fns_test.cc` string and find it in the BUILD file . Then I can't find any hint. – DunkOnly Oct 16 '16 at 13:23
  • Now I know I should build it first : `bazel build //tensorflow/core:framework_common_shape_fns_test` . Then I can run it : `bazel-bin/tensorflow/core/framework_common_shape_fns_test` – DunkOnly Oct 18 '16 at 04:37

1 Answers1

2

To summarize:

  • you have to make sure the test binary is built first: either by running bazel test <target> or with bazel build <target> or with bazel build -c dbg <target>. The last one gives fully debuggable executables that give you line numbers in gdb backtrace.
  • The binary is in the same directory as the BUILD file (ie, if you have tensorflow/core/BUILD, then the binary will be under bazel-bin/tensorflow/core)
  • You can find the name of bazel that includes given .cc file by using bazel query. IE, for common_shape_fns_test you can find that target name is //tensorflow/core:framework_common_shape_fns_test by using command below

.

fullname=$(bazel query tensorflow/core/framework/common_shape_fns_test.cc)
bazel query "attr('srcs', $fullname, ${fullname//:*/}:*)"
Yaroslav Bulatov
  • 57,332
  • 22
  • 139
  • 197