plasma-umass / DoubleTake

Evidence-based dynamic analysis: a fast checker for memory errors.
MIT License
21 stars 12 forks source link

RFC: build: simple non-recursive Makefile & unit testing framework #24

Closed bpowers closed 9 years ago

bpowers commented 9 years ago

I realize this is somewhat disruptive, but I think there are some nice benefits:

Quiet build output, but ability to see exact command executed without editing the Makefile:

[bpowers@vyse DoubleTake]$ make
  CXX   build/leakcheck.o
  CXX   build/xthread.o
  CXX   build/internalsyncs.o
  CXX   build/memtrack.o
  CXX   build/xrun.o
  CXX   build/selfmap.o
  CXX   build/quarantine.o
  CXX   build/libdoubletake.o
  CXX   build/real.o
  CXX   build/log.o
  CXX   build/watchpoint.o
  CXX   build/xmemory.o
  LD    libdoubletake.so
  LD    tests/simple_leak/simple.test
  LD    tests/simple_overflow/simple.test
  LD    tests/simple_uaf/simple.test
  CXX   tests/unit/bitmap.o
  CXX   tests/unit/gtest-all.o
  CXX   tests/unit/gtest_main.o
  AR    libdttest_s.a
  LD    tests/unit/unit.test

[bpowers@vyse DoubleTake]$ touch source/log.cpp && make unit-tests V=1
  CXX   build/log.o
clang++ -O0 -std=c++11 -g -pedantic -fPIC -fno-omit-frame-pointer -D_DEFAULT_SOURCE -D_BSD_SOURCE -Werror -Wall -Wextra -Wpedantic -Wundef -Wno-unused-parameter -Wno-format-pedantic -Wno-nested-anon-types -DDEBUG_LEVEL=3 -DDETECT_OVERFLOW -DDETECT_USAGE_AFTER_FREE  -Iinclude -Iheaplayers -MMD -o build/log.o -c source/log.cpp
  AR    libdttest_s.a
ar rcD libdttest_s.a build/leakcheck.o build/xthread.o build/internalsyncs.o build/memtrack.o build/xrun.o build/selfmap.o build/quarantine.o build/real.o build/log.o build/watchpoint.o build/xmemory.o
ranlib libdttest_s.a
  LD    tests/unit/unit.test
clang++ -O0 -g -pedantic -fPIC -fno-omit-frame-pointer -D_DEFAULT_SOURCE -D_BSD_SOURCE -Werror -Wall -Wextra -Wpedantic -Wundef -Wno-unused-parameter -Wno-format-pedantic -Wno-nested-anon-types -DDEBUG_LEVEL=3 -DDETECT_OVERFLOW -DDETECT_USAGE_AFTER_FREE  -Iinclude -Iheaplayers -MMD -o tests/unit/unit.test tests/unit/bitmap.o tests/unit/gtest-all.o tests/unit/gtest_main.o  -L. -ldttest_s -ldl -lpthread
./tests/unit/unit.test
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from BitmapTest
[ RUN      ] BitmapTest.SetGet
[       OK ] BitmapTest.SetGet (981 ms)
[----------] 1 test from BitmapTest (981 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (981 ms total)
[  PASSED  ] 1 test.

Ability to switch target arch without editing the makefile:

    $ make ARCH=x86 -j4 clean all

But I think the biggest improvement is correct dependency chaining across directories:

MBP 01:05:57 (_build) [bpowers@vyse DoubleTake]$ touch source/log.cpp && make simple-tests -j4
  CXX   build/log.o
  LD    libdoubletake.so
  LD    tests/simple_leak/simple.test
  LD    tests/simple_uaf/simple.test
  LD    tests/simple_overflow/simple.test
  TEST  simple_overflow
  TEST  simple_leak
  TEST  simple_uaf

And everything depends on the Makefile. This means if you change a compile-time flag like DEBUG_LEVEL or DETECT_USE_AFTER_FREE in the Makefile, you don't have to worry about manually cleaning out the last build - all of libdoubletake will automatically be rebuilt. (This is huge for my personal productivity - no more 20 minutes spent wondering why some output is wrong, and finding out I forgot to clean out the old object files). This should allow for a nicer development workflow.

Please let me know if there are concerns or questions. I need to do more testing - I've only run this on my own machines.