minimalist hardware testing support
Dependents: MAX5715BOB_Tester MAX11131BOB_Tester MAX5171BOB_Tester MAX11410BOB_Tester ... more
Diff: MaximTinyTester.cpp
- Revision:
- 5:67a1cd5a67cc
- Parent:
- 3:080aa1bb1bc0
- Child:
- 6:3d50dda3d0eb
--- a/MaximTinyTester.cpp Fri Sep 27 21:16:09 2019 -0700 +++ b/MaximTinyTester.cpp Thu Jan 30 23:56:17 2020 +0000 @@ -278,6 +278,90 @@ //~ associatedCmdLine.serial().printf("\r\n"); } +/** Test a software function +* +* @param[in] nameOfFunctionUnderTest is the user-facing name of the function under test +* +* @param[in] functionUnderTest points to the function under test +* +* @param[in] value_u32 is a test argument given to the function under test +* +* @param[in] expect_result contains the expected result +* +* @pre err_threshold determines how closely the result must match the expected value +* +* @post nPass and nFail counters are updated +* +* @return true if success, false if test failed +* +*/ +bool MaximTinyTester::FunctionCall_Expect(const char *nameOfFunctionUnderTest, + Callback<double(uint32_t)> functionUnderTest, + uint32_t value_u32, double expect_result) +{ + double actual_result = functionUnderTest(value_u32); + double err_result = (actual_result - expect_result); + if (( -err_threshold < err_result) && ( err_result < err_threshold)) + { + PASS(); + associatedCmdLine.serial().printf("%s(%d)", nameOfFunctionUnderTest, value_u32); + associatedCmdLine.serial().printf(" expect %6.6f", expect_result); + return true; + } + else + { + FAIL(); + associatedCmdLine.serial().printf("%s(%d)", nameOfFunctionUnderTest, value_u32); + associatedCmdLine.serial().printf(" expect %6.6f", expect_result); + associatedCmdLine.serial().printf(" but got %6.6f", actual_result); + associatedCmdLine.serial().printf(" err=%6.6f", err_result); + return false; + } + //~ associatedCmdLine.serial().printf("\r\n"); +} + +/** Test a software function +* +* @param[in] nameOfFunctionUnderTest is the user-facing name of the function under test +* +* @param[in] functionUnderTest points to the function under test +* +* @param[in] value_d is a test argument given to the function under test +* +* @param[in] expect_result contains the expected result +* +* @pre err_threshold determines how closely the result must match the expected value +* +* @post nPass and nFail counters are updated +* +* @return true if success, false if test failed +* +*/ +bool MaximTinyTester::FunctionCall_Expect(const char *nameOfFunctionUnderTest, + Callback<double(double)> functionUnderTest, + double value_d, double expect_result) +{ + double actual_result = functionUnderTest(value_d); + double err_result = (actual_result - expect_result); + if (( -err_threshold < err_result) && ( err_result < err_threshold)) + { + PASS(); + associatedCmdLine.serial().printf("%s(%d)", nameOfFunctionUnderTest, value_d); + associatedCmdLine.serial().printf(" expect %6.6f", expect_result); + return true; + } + else + { + FAIL(); + associatedCmdLine.serial().printf("%s(%d)", nameOfFunctionUnderTest, value_d); + associatedCmdLine.serial().printf(" expect %6.6f", expect_result); + associatedCmdLine.serial().printf(" but got %6.6f", actual_result); + associatedCmdLine.serial().printf(" err=%6.6f", err_result); + return false; + } + //~ associatedCmdLine.serial().printf("\r\n"); +} + /** Test an analog voltage input to the platform (output from the device under test) * * @param[in] expect_result contains the expected voltage