p≡p engine fork for my own dirty testing of stuff
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

210 lines
6.3 KiB

3 years ago
3 years ago
2 years ago
  1. # Building and Running the Tests for the p≡p Engine
  2. Work in progress.
  3. ## Caveat, before you begin
  4. Right now, the engine tests only function on \*nix-like systems (including
  5. MacOS).
  6. *(Conversion to Windows will require, at the very least, looking at some of the
  7. file-handling code. If you want to fix this, start by looking in Engine.cc
  8. in the test/src directory!)*
  9. ## Requirements
  10. In addition to the engine requirements, you will need:
  11. * `cmake`
  12. * `python3`
  13. * `git` (for getting the `gtest-parallel` repository, unless you grab the
  14. tarball from somewhere)
  15. ## Building the prerequisites
  16. The Engine test suite now requires (at least) two additional pieces to run:
  17. * `googletest`
  18. * `gtest-parallel`
  19. How this proceeds depends on your platform and whether or not you use a packaged
  20. distribution.
  21. These instructions do this with `cmake`. If you can manage it with `bazel`
  22. instead, more power to you ;)
  23. ### Installing `googletest`
  24. #### Packaged distributions
  25. This is the currently preferred way to do this, because everyone was doing it
  26. anyway and who am I to judge?
  27. ##### Debian and Ubuntu (and derivatives)
  28. Thanks to Erik Smistad for this starting point (condensed from [Getting Started
  29. with Google Test On
  30. Ubuntu](https://www.eriksmistad.no/getting-started-with-google-test-on-ubuntu/)):
  31. 1. Install the packages `cmake` and `libgtest-dev` from the repository. This
  32. will install the gtest source files to `/usr/src/gtest`. You'll still need to
  33. compile the code and link the library files to be able to use them.
  34. 2. Compile the source files:
  35. ```
  36. cd /usr/src/gtest
  37. sudo cmake CMakeLists.txt
  38. sudo make
  39. ```
  40. 3. Copy/symlink the libraries to the library location of your choice (here,
  41. it's `/usr/lib`, hence the `sudo`, but as long as it's in your library path,
  42. it shouldn't matter where you stick it):
  43. ```
  44. sudo cp *.a /usr/lib
  45. ```
  46. ##### MacOS
  47. 1. Install package `gtest` from Macports
  48. 2. Macports will build the libraries for you.
  49. 3. In the next major section ("Building the Test Suite"), under
  50. "Makefile and local.conf", set `GTEST_SRC_DIR` to
  51. `/opt/local/src/googletest` in `local.conf` (see instructions below)
  52. 4. Make sure `/opt/local/lib` is in your library path when compiling and
  53. linking the tests.
  54. #### Downloading and compiling the source yourself
  55. 1. Get the source, Fred. (Luke is tired of the source, I hear.)
  56. ```
  57. git clone https://github.com/google/googletest.git
  58. ```
  59. 2. Switch into the source directory and find the directory
  60. containing the `src` and `include` directories. Mark this directory
  61. for later. (For me, this is `./googletest/googletest`)
  62. 3. Edit `CMakeLists.txt` here to contain the following line at the top:
  63. ```
  64. set (CMAKE_CXX_STANDARD 11)
  65. ```
  66. (If you don't, it won't compile, and I will shake my fist at you.)
  67. 4. Execute, in this directory:
  68. ```
  69. cmake CMakeLists.txt
  70. make
  71. ```
  72. 5. In the lib directory of your current directory are located the
  73. library files you'll use (`lib/*.a`). Copy or symlink them to the library
  74. location of your choice (make sure this is a directory that can be seen
  75. during the test build process - i.e. one that's in one of the library paths
  76. used in building. Mine are located in `$HOME/lib`.
  77. 6. See `Makefile` and `local.conf` under "Building the test suite" below -
  78. In this scenario, I set `GTEST_SRC_DIR` as `<clone_path>/googletest/googletest`
  79. (i.e. the absolute path of where the `src` and `include` directories were
  80. above - for me, `/Users/krista/googletest/googletest`).
  81. ### Installing `gtest-parallel`
  82. Pick a source directory and put your `gtest-parallel` source there
  83. (e.g. via `git clone https://github.com/google/gtest-parallel.git`).
  84. We'll deal more with this when preparing to compile the test suite.
  85. ## Building the test suite
  86. ### `Makefile` and `local.conf`
  87. So `local.conf` in the top-level engine directory is where we stick all of the
  88. Makefile overrides. The test Makefile contains some defaults for relevant
  89. variables here, but if you need to override them, please either create or modify
  90. `local.conf` in the top-level engine directory as needed. The relevant variables
  91. are:
  92. * `GTEST_SRC_DIR`: This is the directory where you compiled googletest above
  93. (defaults to `/usr/src/gtest`)
  94. * `GTEST_INC_DIR`: This is where the include files for googletest are located
  95. (defaults to `$(GTEST_SRC_DIR)/include`)
  96. * `GTEST_PL`: This is the full path to the *python file* for `gtest_parallel`
  97. (default presumes you cloned it under `src` in your home directory, i.e. it is
  98. `$(HOME)/src/gtest-parallel/gtest_parallel.py`)
  99. ### Building
  100. Presuming the above works, then from the top test directory, simply run make.
  101. ## Running the test suite
  102. ### To simply run the test suite and see what tests fail...
  103. Do one of:
  104. 1. `make test` OR
  105. 2. `python3 <path to gtest-parallel.py> ./EngineTests`
  106. ### To run individual test suites, especially for debugging purposes
  107. Note that for some test suites, this will, if something goes dreadfully wrong,
  108. mean that one test's failure may pollute another test. This generally means you
  109. have found a dastardly bug in the engine, but it can also be a test issue.
  110. *Caveat lector*.
  111. 1. To run sequentially, *in the same process*:
  112. ```
  113. ./EngineTests --gtest_filter=TestSuiteName*
  114. ```
  115. For example, for `DeleteKeyTest`:
  116. ```
  117. ./EngineTests DeleteKeyTest*
  118. ```
  119. 2. To debug the same with lldb:
  120. ```
  121. lldb ./EngineTests -- --gtest_filter=TestSuiteName*
  122. ```
  123. 3. To debug with gdb:
  124. ```
  125. gdb --args ./EngineTests --gtest_filter=TestSuiteName*
  126. ```
  127. ### To run and/or debug individual test cases
  128. 1. To run:
  129. ```
  130. ./EngineTests --gtest_filter=TestSuiteName.test_function_name
  131. ```
  132. For example, for `check_delete_single_pubkey` in `DeleteKeyTest`:
  133. ```
  134. ./EngineTests DeleteKeyTest.check_delete_single_pubkey
  135. ```
  136. 2. To debug the same with lldb:
  137. ```
  138. lldb ./EngineTests -- --gtest_filter=TestSuiteName.test_function_name
  139. ```
  140. 3. To debug with gdb:
  141. ```
  142. gdb --args ./EngineTests --gtest_filter=TestSuiteName.test_function_name
  143. ```
  144. When debugging a failing test, use '--gtest_break_on_failure' to have
  145. gtest automatically break into the debugger where the assertion fails.
  146. # Creating new tests
  147. Script next on the agenda...
  148. # Known Problems
  149. The normal run of the tests in parallel eats output. Try running the individual test case as above if you need to see a test case's output.