Fork to see if I can get working
Dependencies: BufferedSerial OneWire WinbondSPIFlash libxDot-dev-mbed5-deprecated
Fork of xDotBridge_update_test20180823 by
testAPI.cpp
00001 /* 00002 * testAPI.cpp 00003 * 00004 * Created on: Feb 3, 2017 00005 * Author: mbriggs 00006 */ 00007 #include "mbed.h" 00008 #include "greentea-client/test_env.h" 00009 #include "unity.h" 00010 #include "utest.h" 00011 #include "rtos.h" 00012 00013 // API under test 00014 #include "DS2408.h" 00015 00016 #define __TEST__ 1 00017 00018 #define USE_RELIABLE 1 00019 00020 using namespace utest::v1; 00021 00022 DigitalOut switchedIO(I2C_SCL, 0); // Always enable Switched IO for test 00023 OneWire OWMaster(I2C_SDA); 00024 uint8_t ds2408Addr[8]; 00025 00026 /** 00027 * A test that the OneWire Device is on the bus. If not all other tests will fail. 00028 */ 00029 void test_search() { 00030 uint8_t result; 00031 for (int i=0; i<10; i++) { 00032 OWMaster.reset(); 00033 OWMaster.reset_search(); // TODO Check if this is helpful 00034 wait(1.0); 00035 result = OWMaster.search(ds2408Addr); 00036 if (result == 1) { 00037 break; 00038 } 00039 } 00040 TEST_ASSERT(result == 1); 00041 } 00042 00043 /** 00044 * Checks that in idle state all the IOs are pulled up. 00045 */ 00046 void test_idle_state() { 00047 DS2408 ds2408(&OWMaster, ds2408Addr); 00048 CmdResult result; 00049 00050 #ifdef USE_RELIABLE 00051 result = ds2408.pioLogicReliableWrite(0xFF); // Leave all IOs high Z e.g. should float high 00052 #else 00053 result = ds2408.pioLogicWrite(0xFF); // Leave all IOs high Z e.g. should float high 00054 #endif 00055 TEST_ASSERT_MESSAGE(result == cmdSuccess, "Error returned during write operation"); 00056 00057 uint8_t val = 0; 00058 #ifdef USE_RELIABLE 00059 result = ds2408.pioLogicReliableRead(val); 00060 #else 00061 result = ds2408.pioLogicRead(val); 00062 #endif 00063 TEST_ASSERT_MESSAGE(result == cmdSuccess, "Error returned during read operation"); 00064 TEST_ASSERT_MESSAGE(val == 0xFF, "Bits not correct"); 00065 } 00066 00067 /** 00068 * This test walks a zero bit for ds2408. Note this requires a ds2408 with all 00069 * IOs pulled up since each will pulled low in sequence. 00070 */ 00071 void test_walk_the_zero() { 00072 DS2408 ds2408(&OWMaster, ds2408Addr); 00073 00074 #ifdef USE_RELIABLE 00075 result = ds2408.pioLogicReliableWrite(0xFF); // Leave all IOs high Z e.g. should float high 00076 #else 00077 result = ds2408.pioLogicWrite(0xFF); // Leave all IOs high Z e.g. should float high 00078 #endif 00079 TEST_ASSERT_MESSAGE(result == cmdSuccess, "Error returned during write operation"); 00080 00081 uint8_t readVal = 0; 00082 #ifdef USE_RELIABLE 00083 result = ds2408.pioLogicReliableRead(readVal); 00084 #else 00085 result = ds2408.pioLogicRead(readVal); 00086 #endif 00087 TEST_ASSERT_MESSAGE(result == cmdSuccess, "Error returned during read operation"); 00088 TEST_ASSERT_MESSAGE(readVal == 0xFF, "Bits not correct"); 00089 00090 uint8_t writeVal; 00091 for (int i=0; i<8; i++) { 00092 writeVal = ~(1 << i); 00093 #ifdef USE_RELIABLE 00094 result = ds2408.pioLogicReliableWrite(writeVal); // Leave all IOs high Z e.g. should float high 00095 #else 00096 result = ds2408.pioLogicWrite(writeVal); // Leave all IOs high Z e.g. should float high 00097 #endif 00098 TEST_ASSERT_MESSAGE(result == cmdSuccess, "Error returned during write operation"); 00099 00100 #ifdef USE_RELIABLE 00101 result = ds2408.pioLogicReliableRead(readVal); 00102 #else 00103 result = ds2408.pioLogicRead(readVal); 00104 #endif 00105 TEST_ASSERT_MESSAGE(result == cmdSuccess, "Error returned during read operation"); 00106 TEST_ASSERT_MESSAGE(readVal == writeVal, "Bits not correct"); 00107 } 00108 } 00109 00110 00111 utest::v1::status_t test_setup(const size_t number_of_cases) { 00112 // Setup Greentea using a reasonable timeout in seconds 00113 GREENTEA_SETUP(40, "default_auto"); 00114 return verbose_test_setup_handler(number_of_cases); 00115 } 00116 00117 // Test cases 00118 Case cases[] = { 00119 Case("Testing search", test_search), 00120 // Case("Testing init", test_init), 00121 Case("Testing idle state", test_idle_state), 00122 Case("Test walking the zero", test_walk_the_zero) 00123 }; 00124 00125 Specification specification(test_setup, cases); 00126 00127 // Entry point into the tests 00128 int main() { 00129 return !Harness::run(specification); 00130 }
Generated on Fri Jul 15 2022 14:36:45 by 1.7.2