Morse Micro IoT SDK  2.9.7
porting_assistant.c
Go to the documentation of this file.
1/*
2 * Copyright 2021-2023 Morse Micro
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
27#include "porting_assistant.h"
28
29#if defined(ENABLE_EXT_XTAL_INIT) && ENABLE_EXT_XTAL_INIT
30/* The crystal initialization requires chip specific configuration which we do not have access
31 * to in the porting assistant example application. */
32#error "With ENABLE_EXT_XTAL_INIT defined this device is not supported by porting assistant."
33#endif
34
35/* Test step declarations */
36extern const struct test_step test_step_os_malloc;
37extern const struct test_step test_step_os_realloc;
38extern const struct test_step test_step_os_time;
39extern const struct test_step test_step_os_task_creation;
41extern const struct test_step test_step_mmhal_wlan_init;
44extern const struct test_step test_step_read_chip_id;
45extern const struct test_step test_step_bulk_write_read;
46extern const struct test_step test_step_raw_tput;
51extern const struct test_step test_step_verify_busy_pin;
55static const struct test_step * const test_steps[] = {
69};
70
73{
75 unsigned no_result;
77 unsigned pass;
79 unsigned fail;
80};
81
89static const char *result_code_to_string(enum test_result result)
90{
91 switch (result)
92 {
93 case TEST_NO_RESULT: return "";
94 case TEST_PASSED: return F_GREEN("PASS");
95 case TEST_SKIPPED: return F_BLUE("SKIP");
96 case TEST_FAILED: return F_RED("FAIL");
97 case TEST_FAILED_NON_CRITICAL: return F_YELLOW("FAIL");
98 }
99 MMOSAL_ASSERT(false);
100}
101
110static void run_test_steps(const struct test_step * const steps[], size_t num_steps,
111 struct test_counters *ctrs)
112{
113 static char log_buf[1024];
114
115 size_t ii;
116 for (ii = 0; ii < num_steps; ii++)
117 {
118 const struct test_step *step = steps[ii];
119 size_t log_buf_len = sizeof(log_buf);
120 log_buf[0] = '\0';
121
122 LOG_PRINTF(F_BOLD("%-60s "), step->description);
123 LOG_FLUSH();
124
125 enum test_result result = step->exec(log_buf, log_buf_len);
126 if (result != TEST_NO_RESULT)
127 {
128 LOG_PRINTF("[ %s ]", result_code_to_string(result));
129 }
130 LOG_WRITE("\n");
131
132 if (log_buf[0] != '\0')
133 {
134 LOG_WRITE("\n");
135 LOG_WRITE(log_buf);
136 }
137
138 switch (result)
139 {
140 case TEST_NO_RESULT: ctrs->no_result++; break;
141 case TEST_PASSED: ctrs->pass++; break;
142 case TEST_SKIPPED: break;
143 case TEST_FAILED: ctrs->fail++; break;
144 case TEST_FAILED_NON_CRITICAL: ctrs->fail++; break;
145 }
146
147 if (result == TEST_FAILED)
148 {
149 break;
150 }
151 }
152}
153
158void app_init(void)
159{
160 /* Having deep sleep enabled can complicate debugging. Given the purpose of this applications
161 * is to validate that you can communicate to the MM-Chip it will be disabled by default. */
163
164 struct test_counters ctrs = { 0 };
165 unsigned num_tests = sizeof(test_steps)/sizeof(test_steps[0]);
166
167 LOG_WRITE(F_BOLD("\n\nMM-IoT-SDK Porting Assistant\n"));
168 LOG_WRITE("----------------------------\n\n");
169 run_test_steps(test_steps, num_tests, &ctrs);
170
171
172 LOG_PRINTF("\n\n%u total test steps. %u passed, %u failed, %u no result, %u skipped\n",
173 num_tests, ctrs.pass, ctrs.fail, ctrs.no_result,
174 num_tests - ctrs.no_result - ctrs.pass - ctrs.fail);
175}
void mmhal_set_deep_sleep_veto(uint8_t veto_id)
Sets a deep sleep veto that will prevent the device from entering deep sleep.
@ MMHAL_VETO_ID_APP_MIN
Start of deep sleep veto ID range that is available for application use.
Definition: mmhal.h:300
#define MMOSAL_ASSERT(expr)
Assert that the given expression evaluates to true and abort execution if not.
Definition: mmosal.h:927
const struct test_step test_step_mmhal_wlan_validate_bcf
Test definition.
const struct test_step test_step_read_chip_id
Test definition.
const struct test_step test_step_os_malloc
Test definition.
const struct test_step test_step_verify_busy_pin
Test definition.
const struct test_step test_step_os_realloc
Test definition.
const struct test_step test_step_mmhal_wlan_sdio_startup
Test definition.
const struct test_step test_step_raw_tput
Test definition.
const struct test_step test_step_mmhal_wlan_validate_fw
Test definition.
const struct test_step test_step_bulk_write_read
Test definition.
const struct test_step test_step_os_time
Test definition.
const struct test_step test_step_mmhal_wlan_hard_reset
Test definition.
static void run_test_steps(const struct test_step *const steps[], size_t num_steps, struct test_counters *ctrs)
Iterate through the given list of test steps and execute until complete or until a critical failure o...
const struct test_step test_step_os_task_creation
Test definition.
void app_init(void)
Main entry point to the application.
static const struct test_step *const test_steps[]
Array of test steps.
const struct test_step test_step_mmhal_wlan_init
Test definition.
static const char * result_code_to_string(enum test_result result)
Convert a test_result code to string.
Counters to track test runs.
unsigned no_result
Number of tests that did not return a pass/fail result.
unsigned pass
Number of tests that passed.
unsigned fail
Number of tests that failed.
Test step descriptor.
const char * description
Short, user friendly description of the test step.
enum test_result(* exec)(char *log_buf, size_t log_buf_len)
Test step execution function.