commit 4c72a54cb0b2745713595adaecfc1bad548c03e0
Author: Thomas Schöpping <tschoepp@cit-ec.uni-bielefeld.de>
Date:   Mon Jul 15 13:21:06 2019 +0200

    Massive overhaul:
    - updated to a new version of AMiRo-LLD
    - tests (formerly unit tests) are now split onto multiple parts:
      - there are "global" tests for each driver etc.
      - there is an individual part for each module, e.g. if there are multiple instances of the same periphery
    - a lot of minor enhancements

diff --git a/modules/DiWheelDrive_1-2/module.c b/modules/DiWheelDrive_1-2/module.c
index 96041bb..70384c5 100644
--- a/modules/DiWheelDrive_1-2/module.c
+++ b/modules/DiWheelDrive_1-2/module.c
@@ -127,7 +127,7 @@ ROMCONST apalControlGpio_t moduleGpioLed = {
   /* GPIO */ &_gpioLed,
   /* meta */ {
     /* direction      */ APAL_GPIO_DIRECTION_OUTPUT,
-    /* active state   */ LED_LLD_GPIO_ACTIVE_STATE,
+    /* active state   */ APAL_GPIO_ACTIVE_LOW,
     /* interrupt edge */ APAL_GPIO_EDGE_NONE,
   },
 };
@@ -367,6 +367,8 @@ AT24C01BDriver moduleLldEeprom = {
   /* I²C address  */ AT24C01B_LLD_I2C_ADDR_FIXED,
 };
 
+// TODO: BNO055
+
 INA219Driver moduleLldPowerMonitorVdd = {
   /* I2C Driver       */ &MODULE_HAL_I2C_PROX_EEPROM_PWRMTR,
   /* I²C address      */ INA219_LLD_I2C_ADDR_FIXED,
@@ -400,295 +402,163 @@ VCNL4020Driver moduleLldProximity = {
 
 /*===========================================================================*/
 /**
- * @name Unit tests (UT)
+ * @name Tests
  * @{
  */
 /*===========================================================================*/
 #if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
-#include <string.h>
 
 /*
  * A3906 (motor driver)
  */
-static int _utShellCmdCb_AlldA3906(BaseSequentialStream* stream, int argc, char* argv[])
+#include <module_test_A3906.h>
+static int _testA3906ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
 {
-  (void)argc;
-  (void)argv;
-  aosUtRun(stream, &moduleUtAlldA3906, NULL);
-  return AOS_OK;
+  return moduleTestA3906ShellCb(stream, argc, argv, NULL);
 }
-static ut_a3906data_t _utA3906Data = {
-  /* driver           */ &moduleLldMotors,
-  /* PWM information  */ {
-    /* driver   */ &MODULE_HAL_PWM_DRIVE,
-    /* channels */ {
-      /* left wheel forward   */ MODULE_HAL_PWM_DRIVE_CHANNEL_LEFT_FORWARD,
-      /* left wheel backward  */ MODULE_HAL_PWM_DRIVE_CHANNEL_LEFT_BACKWARD,
-      /* right wheel forward  */ MODULE_HAL_PWM_DRIVE_CHANNEL_RIGHT_FORWARD,
-      /* right wheel backward */ MODULE_HAL_PWM_DRIVE_CHANNEL_RIGHT_BACKWARD,
-    },
-  },
-  /* QEI information  */ {
-    /* left wheel               */ &MODULE_HAL_QEI_LEFT_WHEEL,
-    /* right wheel              */ &MODULE_HAL_QEI_RIGHT_WHEEL,
-    /* increment per revolution */ MODULE_HAL_QEI_INCREMENTS_PER_REVOLUTION,
-  },
-  /* Wheel diameter   */ {
-    /* left wheel   */ 0.05571f,
-    /* right wheel  */ 0.05571f,
-  },
-  /* timeout          */ 10 * MICROSECONDS_PER_SECOND,
-};
-aos_unittest_t moduleUtAlldA3906  = {
-  /* name           */ "A3906",
-  /* info           */ "motor driver",
-  /* test function  */ utAlldA3906Func,
-  /* shell command  */ {
-    /* name     */ "unittest:MotorDriver",
-    /* callback */ _utShellCmdCb_AlldA3906,
-    /* next     */ NULL,
-  },
-  /* data           */ &_utA3906Data,
-};
+AOS_SHELL_COMMAND(moduleTestA3906ShellCmd, "test:MotorDriver", _testA3906ShellCmdCb);
 
 /*
- * AT24C01B (EEPROM)
+ * AT24C01BN-SH-B (EEPROM)
  */
-static int _utShellCmdCb_AlldAt24c01b(BaseSequentialStream* stream, int argc, char* argv[])
+#include <module_test_AT24C01B.h>
+static int _testAt24co1bShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
 {
-  (void)argc;
-  (void)argv;
-  aosUtRun(stream, &moduleUtAlldAt24c01b, NULL);
-  return AOS_OK;
+  return moduleTestAt24c01bShellCb(stream, argc, argv, NULL);
 }
-static ut_at24c01bdata_t _utAlldAt24c01bData = {
-  /* driver   */ &moduleLldEeprom,
-  /* timeout  */ MICROSECONDS_PER_SECOND,
-};
-aos_unittest_t moduleUtAlldAt24c01b = {
-  /* name           */ "AT24C01B",
-  /* info           */ "1kbit EEPROM",
-  /* test function  */ utAlldAt24c01bFunc,
-  /* shell command  */ {
-    /* name     */ "unittest:EEPROM",
-    /* callback */ _utShellCmdCb_AlldAt24c01b,
-    /* next     */ NULL,
-  },
-  /* data           */ &_utAlldAt24c01bData,
-};
+AOS_SHELL_COMMAND(moduleTestAt24c01bShellCmd, "test:EEPROM", _testAt24co1bShellCmdCb);
+
+// TODO: BNO055
 
 /*
  * INA219 (power monitor)
  */
-static int _utShellCmdCb_AlldIna219(BaseSequentialStream* stream, int argc, char* argv[])
+#include <module_test_INA219.h>
+static int _testIna219ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
 {
-  (void)argc;
-  (void)argv;
-  aosUtRun(stream, &moduleUtAlldIna219, "VDD (3.3V)");
-  return AOS_OK;
+  return moduleTestIna219ShellCb(stream, argc, argv, NULL);
 }
-static ut_ina219data_t _utIna219Data = {
-  /* driver           */ &moduleLldPowerMonitorVdd,
-  /* expected voltage */ 3.3f,
-  /* tolerance        */ 0.05f,
-  /* timeout */ MICROSECONDS_PER_SECOND,
-};
-aos_unittest_t moduleUtAlldIna219 = {
-  /* name           */ "INA219",
-  /* info           */ "power monitor",
-  /* test function  */ utAlldIna219Func,
-  /* shell command  */ {
-    /* name     */ "unittest:PowerMonitor",
-    /* callback */ _utShellCmdCb_AlldIna219,
-    /* next     */ NULL,
-  },
-  /* data           */ &_utIna219Data,
-};
+AOS_SHELL_COMMAND(moduleTestIna219ShellCmd, "test:PowerMonitor", _testIna219ShellCmdCb);
 
 /*
  * Status LED
  */
-static int _utShellCmdCb_AlldLed(BaseSequentialStream* stream, int argc, char* argv[])
+#include <module_test_LED.h>
+static int _testLedShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
 {
-  (void)argc;
-  (void)argv;
-  aosUtRun(stream, &moduleUtAlldLed, NULL);
-  return AOS_OK;
+  return moduleTestLedShellCb(stream, argc, argv, NULL);
 }
-aos_unittest_t moduleUtAlldLed = {
-  /* name           */ "LED",
-  /* info           */ NULL,
-  /* test function  */ utAlldLedFunc,
-  /* shell command  */ {
-    /* name     */ "unittest:StatusLED",
-    /* callback */ _utShellCmdCb_AlldLed,
-    /* next     */ NULL,
-  },
-  /* data           */ &moduleLldStatusLed,
-};
+AOS_SHELL_COMMAND(moduleTestLedShellCmd, "test:StatusLED", _testLedShellCmdCb);
 
 /*
  * LTC4412 (power path controller)
  */
-static int _utShellCmdCb_AlldLtc4412(BaseSequentialStream* stream, int argc, char* argv[])
+#include <module_test_LTC4412.h>
+static int _testLtc4412ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
 {
-  (void)argc;
-  (void)argv;
-  aosUtRun(stream, &moduleUtAlldLtc4412, NULL);
-  return AOS_OK;
+  return moduleTestLtc4412ShellCb(stream, argc, argv, NULL);
 }
-aos_unittest_t moduleUtAlldLtc4412 = {
-  /* name           */ "LTC4412",
-  /* info           */ "Power path controller",
-  /* test function  */ utAlldLtc4412Func,
-  /* shell command  */ {
-    /* name     */ "unittest:PowerPathController",
-    /* callback */ _utShellCmdCb_AlldLtc4412,
-    /* next     */ NULL,
-  },
-  /* data           */ &moduleLldPowerPathController,
-};
+AOS_SHELL_COMMAND(moduleTestLtc4412ShellCmd, "test:PowerPathController", _testLtc4412ShellCmdCb);
 
 /*
  * PCA9544A (I2C multiplexer)
  */
-static int _utShellCmdCb_AlldPca9544a(BaseSequentialStream* stream, int argc, char* argv[])
+#include <module_test_PCA9544A.h>
+static int _testPca9544aShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
 {
-  (void)argc;
-  (void)argv;
-  aosUtRun(stream, &moduleUtAlldPca9544a, NULL);
-  return AOS_OK;
+  return moduleTestPca9544aShellCb(stream, argc, argv, NULL);
 }
-static ut_pca9544adata_t _utPca9544aData = {
-  /* driver  */ &moduleLldI2cMultiplexer,
-  /* timeout */ MICROSECONDS_PER_SECOND,
-};
-aos_unittest_t moduleUtAlldPca9544a = {
-  /* name           */ "PCA9544A",
-  /* info           */ "I2C multiplexer",
-  /* test function  */ utAlldPca9544aFunc,
-  /* shell command  */ {
-    /* name     */ "unittest:I2CMultiplexer",
-    /* callback */ _utShellCmdCb_AlldPca9544a,
-    /* next     */ NULL,
-  },
-  /* data           */ &_utPca9544aData,
-};
+AOS_SHELL_COMMAND(moduleTestPca9544aShellCmd, "test:I2CMultiplexer", _testPca9544aShellCmdCb);
 
 /*
  * TPS62113 (step-down converter)
  */
-static int _utShellCmdCb_AlldTps62113(BaseSequentialStream* stream, int argc, char* argv[])
+#include <module_test_TPS6211x.h>
+static int _testTps6211xShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
 {
-  (void)argc;
-  (void)argv;
-  aosUtRun(stream, &moduleUtAlldTps62113, NULL);
-  return AOS_OK;
+  return moduleTestTps6211xShellCb(stream, argc, argv, NULL);
 }
-aos_unittest_t moduleUtAlldTps62113 = {
-  /* name           */ "TPS62113",
-  /* info           */ "Step down converter",
-  /* test function  */ utAlldTps6211xFunc,
-  /* shell command  */ {
-    /* name     */ "unittest:StepDownConverter",
-    /* callback */ _utShellCmdCb_AlldTps62113,
-    /* next     */ NULL,
-  },
-  /* data           */ &moduleLldStepDownConverterVdrive,
-};
+AOS_SHELL_COMMAND(moduleTestTps62113ShellCmd, "test:StepDownConverter", _testTps6211xShellCmdCb);
 
 /*
  * VCNL4020 (proximity sensor)
  */
-static void _utAlldVcnl4020_disableInterrupt(VCNL4020Driver* vcnl)
+#include <module_test_VCNL4020.h>
+static int _testVcnl4020ShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
 {
-  uint8_t intstatus;
-  vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTCTRL, 0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
-  vcnl4020_lld_readreg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, &intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
-  if (intstatus) {
-    vcnl4020_lld_writereg(vcnl, VCNL4020_LLD_REGADDR_INTSTATUS, intstatus, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
-  }
-  return;
+  return moduleTestVcnl4020ShellCb(stream, argc, argv, NULL);
 }
-static int _utShellCmdCb_AlldVcnl4020(BaseSequentialStream* stream, int argc, char* argv[])
+AOS_SHELL_COMMAND(moduleTestVcnl4020ShellCmd, "test:ProximitySensor", _testVcnl4020ShellCmdCb);
+
+/*
+ * entire module
+ */
+static int _testAllShellCmdCb(BaseSequentialStream* stream, int argc, char* argv[])
 {
-  enum {
-    UNKNOWN,
-    FL, FR, WL, WR,
-  } sensor = UNKNOWN;
-  // evaluate arguments
-  if (argc == 2) {
-    if (strcmp(argv[1], "--frontleft") == 0 || strcmp(argv[1], "-fl") == 0) {
-      sensor = FL;
-    } else if (strcmp(argv[1], "--frontright") == 0 || strcmp(argv[1], "-fr") == 0) {
-      sensor = FR;
-    } else if (strcmp(argv[1], "--wheelleft") == 0 || strcmp(argv[1], "-wl") == 0) {
-      sensor = WL;
-    } else if (strcmp(argv[1], "--wheelright") == 0 || strcmp(argv[1], "-wr") == 0) {
-      sensor = WR;
-    }
-  }
-  if (sensor != UNKNOWN) {
-    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
-    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
-    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
-    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
-    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
-    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
-    pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
-    _utAlldVcnl4020_disableInterrupt(((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->vcnld);
-    switch (sensor) {
-      case FL:
-        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH3, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
-        aosUtRun(stream, &moduleUtAlldVcnl4020, "front left sensor");
-        break;
-      case FR:
-        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH0, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
-        aosUtRun(stream, &moduleUtAlldVcnl4020, "front right sensor");
-        break;
-      case WL:
-        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH2, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
-        aosUtRun(stream, &moduleUtAlldVcnl4020, "left wheel sensor");
-        break;
-      case WR:
-        pca9544a_lld_setchannel(&moduleLldI2cMultiplexer, PCA9544A_LLD_CH1, ((ut_vcnl4020data_t*)moduleUtAlldVcnl4020.data)->timeout);
-        aosUtRun(stream, &moduleUtAlldVcnl4020, "right wheel sensor");
-        break;
-      default:
-        break;
-    }
-    return AOS_OK;
-  }
-  // print help
-  chprintf(stream, "Usage: %s OPTION\n", argv[0]);
-  chprintf(stream, "Options:\n");
-  chprintf(stream, "  --frontleft, -fl\n");
-  chprintf(stream, "    Test front left proximity sensor.\n");
-  chprintf(stream, "  --frontrigt, -fr\n");
-  chprintf(stream, "    Test front right proximity sensor.\n");
-  chprintf(stream, "  --wheelleft, -wl\n");
-  chprintf(stream, "    Test left wheel proximity sensor.\n");
-  chprintf(stream, "  --wheelright, -wr\n");
-  chprintf(stream, "    Test right wheel proximity sensor.\n");
-  return AOS_INVALIDARGUMENTS;
+  (void)argc;
+  (void)argv;
+
+  int status = AOS_OK;
+  char* targv[AMIROOS_CFG_SHELL_MAXARGS] = {NULL};
+  aos_testresult_t result_test = {0, 0};
+  aos_testresult_t result_total = {0, 0};
+
+  /* A3906 (motor driver) */
+  status |= moduleTestA3906ShellCb(stream, 0, targv, &result_test);
+  result_total = aosTestResultAdd(result_total, result_test);
+
+  /* AT24C01B (EEPROM) */
+  status |= moduleTestAt24c01bShellCb(stream, 0, targv, &result_test);
+  result_total = aosTestResultAdd(result_total, result_test);
+
+  // TODO: BNO055
+
+  /* INA219 (power monitor) */
+  status |= moduleTestIna219ShellCb(stream, 0, targv, &result_test);
+  result_total = aosTestResultAdd(result_total, result_test);
+
+  /* Status LED */
+  status |= moduleTestLedShellCb(stream, 0, targv, &result_test);
+  result_total = aosTestResultAdd(result_total, result_test);
+
+  /* LTC4412 (power path controller) */
+  status |= moduleTestLtc4412ShellCb(stream, 0, targv, &result_test);
+  result_total = aosTestResultAdd(result_total, result_test);
+
+  /* PCA9544A (I2C multiplexer) */
+  status |= moduleTestPca9544aShellCb(stream, 0, targv, &result_test);
+  result_total = aosTestResultAdd(result_total, result_test);
+
+  /* TPS62113 (step-down converter) */
+  status |= moduleTestTps6211xShellCb(stream, 0, targv, &result_test);
+  result_total = aosTestResultAdd(result_total, result_test);
+
+  /* VCNL4020 (proximity sensor) */
+  // wheel left
+  targv[1] = "-wl";
+  status |= moduleTestVcnl4020ShellCb(stream, 2, targv, &result_test);
+  result_total = aosTestResultAdd(result_total, result_test);
+  // front left
+  targv[1] = "-fl";
+  status |= moduleTestVcnl4020ShellCb(stream, 2, targv, &result_test);
+  result_total = aosTestResultAdd(result_total, result_test);
+  // front right
+  targv[1] = "-fr";
+  status |= moduleTestVcnl4020ShellCb(stream, 2, targv, &result_test);
+  result_total = aosTestResultAdd(result_total, result_test);
+  // wheel right
+  targv[1] = "-wr";
+  status |= moduleTestVcnl4020ShellCb(stream, 2, targv, &result_test);
+  result_total = aosTestResultAdd(result_total, result_test);
+  targv[1] = "";
+
+  // print total result
+  chprintf(stream, "\n");
+  aosTestResultPrintSummary(stream, &result_total, "entire module");
+
+  return status;
 }
-static ut_vcnl4020data_t _utVcnl4020Data = {
-  /* driver       */ &moduleLldProximity,
-  /* timeout      */ MICROSECONDS_PER_SECOND,
-  /* event source */ &aos.events.io,
-  /* event flags  */ MODULE_OS_IOEVENTFLAGS_IRINT,
-};
-aos_unittest_t moduleUtAlldVcnl4020 = {
-  /* name           */ "VCNL4020",
-  /* info           */ "proximity sensor",
-  /* test function  */ utAlldVcnl4020Func,
-  /* shell command  */ {
-    /* name     */ "unittest:Proximity",
-    /* callback */ _utShellCmdCb_AlldVcnl4020,
-    /* next     */ NULL,
-  },
-  /* data           */ &_utVcnl4020Data,
-};
+AOS_SHELL_COMMAND(moduleTestAllShellCmd, "test:all", _testAllShellCmdCb);
 
 #endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
 
