|
| 1 | +# Test with TD Payload |
| 2 | +TD-Shim has some test cases rely on TDX specific environment. Therefore, this simple test framework is created to support the test. |
| 3 | + |
| 4 | +## Test framework code structure |
| 5 | +All codes of test framework are located in [tests/test-td-payload](../tests/test-td-payload). |
| 6 | + |
| 7 | +``` |
| 8 | +-- tests |
| 9 | +---- test-td-payload |
| 10 | +------ main.rs |
| 11 | +------ lib.rs |
| 12 | +------ test.json |
| 13 | +------ testtdinfo.rs |
| 14 | +------ ... |
| 15 | +``` |
| 16 | + |
| 17 | +[main.rs](../tests/test-td-payload/src/main.rs): It defines strut `TestCases`. Main flow: Init `td_logger`-> Init heap-> Init `TestSuite` -> Build test cases(Parse test configuration data in CFV) -> Add test cases in `TestSuite` -> Run test cases -> Log test result. |
| 18 | + |
| 19 | +[lib.rs](../tests/test-td-payload/src/lib.rs):It defines enum `TestResult`、trait `TestCase` 、struct `TestSuite` and `TestSuite.run`. `TestSuite.run` will log result of each test case and count summary test result. |
| 20 | + |
| 21 | +[test.json](../tests/test-td-payload/src/test.json): This is a json format test configuration data file. The structure should be correspond with struct `TestCases` in main.rs. It will be enrolled in CFV with tool [td-shim-enroll](../td-shim-tools/src/bin/td-shim-enroll/main.rs). |
| 22 | + |
| 23 | +[testtdinfo.rs](../tests/test-td-payload/src/testtdinfo.rs): This is a test case sample. Implement test struture and the `TestCase` trait(`setup` `run` `teardown` `get_name` `get_result`) for test structure. |
| 24 | + |
| 25 | +## Build Test Image with Test TD Payload |
| 26 | +Refer to [README](../README.md), using PE as example: |
| 27 | +### Build test TD payload |
| 28 | +``` |
| 29 | +$ cd tests |
| 30 | +$ cargo xbuild -p test-td-payload --target x86_64-unknown-uefi --release --features=main,tdx |
| 31 | +$ cd .. |
| 32 | +``` |
| 33 | + |
| 34 | +### Generate final.bin |
| 35 | +``` |
| 36 | +$ cargo xbuild -p td-shim --target x86_64-unknown-uefi --release --features=main,tdx |
| 37 | +$ cargo run -p td-shim-tools --bin td-shim-ld -- target/x86_64-unknown-uefi/release/ResetVector.bin target/x86_64-unknown-uefi/release/td-shim.efi target/x86_64-unknown-uefi/release/test-td-payload.efi -o target/x86_64-unknown-uefi/release/final-pe.bin |
| 38 | +``` |
| 39 | + |
| 40 | +### Enroll json file in CFV |
| 41 | +``` |
| 42 | +$ cargo run -p td-shim-tools --features="enroller" --bin td-shim-enroll target/x86_64-unknown-uefi/release/final-pe.bin -f F10E684E-3ABD-20E4-5932-8F973C355E57 tests/test-td-payload/src/test.json -o target/x86_64-unknown-uefi/release/final.test.bin |
| 43 | +``` |
| 44 | + |
| 45 | +The output file **final.test.bin** with [test.json](../tests/test-td-payload/src/test.json) is located in the same folder with input final.bin. |
| 46 | + |
| 47 | +## Json Test Configuration Data Example |
| 48 | +``` |
| 49 | +{ |
| 50 | + "tcs001": { |
| 51 | + "name": "tdinfo001", |
| 52 | + "expected": { |
| 53 | + "gpaw": 52, |
| 54 | + "attributes": 0, |
| 55 | + "max_vcpus": 1, |
| 56 | + "num_vcpus": 1, |
| 57 | + "rsvd": [0,0,0] |
| 58 | + }, |
| 59 | + "result": "None", |
| 60 | + "run": true |
| 61 | + } |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +## Test Result Show |
| 66 | +``` |
| 67 | +INFO - --------------------------------------------- |
| 68 | +INFO - Start to run tests. |
| 69 | +INFO - --------------------------------------------- |
| 70 | +INFO - [Test: tdinfo001] |
| 71 | +INFO - td_info data addr: 0x3f7ff9e8 |
| 72 | +INFO - gpaw - 52 |
| 73 | +INFO - max_vcpus - 1 |
| 74 | +INFO - num_vcpus - 1 |
| 75 | +INFO - rsvd - [0, 0, 0] |
| 76 | +INFO - [Test: tdinfo001] - Pass |
| 77 | +INFO - --------------------------------------------- |
| 78 | +INFO - [Test: tdinfo002] |
| 79 | +INFO - td_info data addr: 0x3f7ff9e8 |
| 80 | +INFO - gpaw - 52 |
| 81 | +INFO - Check max_vcpus fail - Expected 8: Actual 1 |
| 82 | +INFO - [Test: tdinfo002] - Fail |
| 83 | +INFO - --------------------------------------------- |
| 84 | +INFO - [Test: tdinfo003] |
| 85 | +INFO - td_info data addr: 0x3f7ff9e8 |
| 86 | +INFO - Check gpaw fail - Expected 48: Actual 52 |
| 87 | +INFO - [Test: tdinfo003] - Fail |
| 88 | +INFO - --------------------------------------------- |
| 89 | +INFO - Test Result: Total run 3 tests; 1 passed; 2 failed |
| 90 | +``` |
0 commit comments