minimalist hardware testing support
Dependents: MAX5715BOB_Tester MAX11131BOB_Tester MAX5171BOB_Tester MAX11410BOB_Tester ... more
Diff: MaximTinyTester.cpp
- Revision:
- 8:9171f0ab3c17
- Parent:
- 7:5b40b6370f8a
- Child:
- 9:3ec00515891d
--- a/MaximTinyTester.cpp Mon Mar 09 23:08:57 2020 -0700 +++ b/MaximTinyTester.cpp Tue Mar 17 04:00:17 2020 +0000 @@ -204,7 +204,7 @@ * * @param[in] functionUnderTest points to the function under test * -* @param[in] voltageV is a test argument given to the function under test +* @param[in] arg_1_voltageV is a test argument given to the function under test * * @param[in] expect_result contains the expected result * @@ -215,13 +215,14 @@ */ bool MaximTinyTester::FunctionCall_Expect(const char *nameOfFunctionUnderTest, Callback<uint16_t(double)> functionUnderTest, - double voltageV, uint16_t expect_result) + double arg_1_voltageV, + uint16_t expect_result) { - uint16_t actual_result = functionUnderTest(voltageV); + uint16_t actual_result = functionUnderTest(arg_1_voltageV); if (actual_result != expect_result) { FAIL(); - associatedCmdLine.serial().printf("%s(%6.4fV)", nameOfFunctionUnderTest, voltageV); + associatedCmdLine.serial().printf("%s(%6.4fV)", nameOfFunctionUnderTest, arg_1_voltageV); associatedCmdLine.serial().printf(" expect %d", expect_result); associatedCmdLine.serial().printf(" but got %d", actual_result); return false; @@ -229,7 +230,7 @@ else { PASS(); - associatedCmdLine.serial().printf("%s(%6.4fV)", nameOfFunctionUnderTest, voltageV); + associatedCmdLine.serial().printf("%s(%6.4fV)", nameOfFunctionUnderTest, arg_1_voltageV); associatedCmdLine.serial().printf(" expect %d", expect_result); return true; } @@ -242,7 +243,7 @@ * * @param[in] functionUnderTest points to the function under test * -* @param[in] value_u16 is a test argument given to the function under test +* @param[in] arg_1_u16 is a test argument given to the function under test * * @param[in] expect_result contains the expected result * @@ -255,21 +256,22 @@ */ bool MaximTinyTester::FunctionCall_Expect(const char *nameOfFunctionUnderTest, Callback<double(uint16_t)> functionUnderTest, - uint16_t value_u16, double expect_result) + uint16_t arg_1_u16, + double expect_result) { - double actual_result = functionUnderTest(value_u16); + double actual_result = functionUnderTest(arg_1_u16); double err_result = (actual_result - expect_result); if (( -err_threshold < err_result) && ( err_result < err_threshold)) { PASS(); - associatedCmdLine.serial().printf("%s(%d)", nameOfFunctionUnderTest, value_u16); + associatedCmdLine.serial().printf("%s(%d)", nameOfFunctionUnderTest, arg_1_u16); associatedCmdLine.serial().printf(" expect %6.6f", expect_result); return true; } else { FAIL(); - associatedCmdLine.serial().printf("%s(%d)", nameOfFunctionUnderTest, value_u16); + associatedCmdLine.serial().printf("%s(%d)", nameOfFunctionUnderTest, arg_1_u16); 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); @@ -284,7 +286,7 @@ * * @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] arg_1_u32 is a test argument given to the function under test * * @param[in] expect_result contains the expected result * @@ -297,21 +299,22 @@ */ bool MaximTinyTester::FunctionCall_Expect(const char *nameOfFunctionUnderTest, Callback<double(uint32_t)> functionUnderTest, - uint32_t value_u32, double expect_result) + uint32_t arg_1_u32, + double expect_result) { - double actual_result = functionUnderTest(value_u32); + double actual_result = functionUnderTest(arg_1_u32); double err_result = (actual_result - expect_result); if (( -err_threshold < err_result) && ( err_result < err_threshold)) { PASS(); - associatedCmdLine.serial().printf("%s(0x%lx)", nameOfFunctionUnderTest, value_u32); + associatedCmdLine.serial().printf("%s(0x%lx)", nameOfFunctionUnderTest, arg_1_u32); associatedCmdLine.serial().printf(" expect %6.6f", expect_result); return true; } else { FAIL(); - associatedCmdLine.serial().printf("%s(0x%lx)", nameOfFunctionUnderTest, value_u32); + associatedCmdLine.serial().printf("%s(0x%lx)", nameOfFunctionUnderTest, arg_1_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); @@ -326,7 +329,7 @@ * * @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] arg_1_d is a test argument given to the function under test * * @param[in] expect_result contains the expected result * @@ -339,21 +342,22 @@ */ bool MaximTinyTester::FunctionCall_Expect(const char *nameOfFunctionUnderTest, Callback<double(double)> functionUnderTest, - double value_d, double expect_result) + double arg_1_d, + double expect_result) { - double actual_result = functionUnderTest(value_d); + double actual_result = functionUnderTest(arg_1_d); double err_result = (actual_result - expect_result); if (( -err_threshold < err_result) && ( err_result < err_threshold)) { PASS(); - associatedCmdLine.serial().printf("%s(%6.6f)", nameOfFunctionUnderTest, value_d); + associatedCmdLine.serial().printf("%s(%6.6f)", nameOfFunctionUnderTest, arg_1_d); associatedCmdLine.serial().printf(" expect %6.6f", expect_result); return true; } else { FAIL(); - associatedCmdLine.serial().printf("%s(%6.6f)", nameOfFunctionUnderTest, value_d); + associatedCmdLine.serial().printf("%s(%6.6f)", nameOfFunctionUnderTest, arg_1_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); @@ -368,6 +372,44 @@ * * @param[in] functionUnderTest points 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<uint8_t()> functionUnderTest, + uint8_t expect_result) +{ + uint8_t actual_result = functionUnderTest(); + if (actual_result != expect_result) + { + FAIL(); + associatedCmdLine.serial().printf("%s()", nameOfFunctionUnderTest); + associatedCmdLine.serial().printf(" expect %d", expect_result); + associatedCmdLine.serial().printf(" but got %d", actual_result); + return false; + } + else + { + PASS(); + associatedCmdLine.serial().printf("%s()", nameOfFunctionUnderTest); + associatedCmdLine.serial().printf(" expect %d", expect_result); + return true; + } + //~ 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] arg_1 is a test argument given to the function under test * * @param[in] expect_result contains the expected result