Morse Micro IoT SDK  2.13.1
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#include "mmhal_core.h"
29#include "mmhal_app.h"
30#include "mmversion.h"
31
32#if defined(ENABLE_EXT_XTAL_INIT) && ENABLE_EXT_XTAL_INIT
33/* The crystal initialization requires chip specific configuration which we do not have access
34 * to in the porting assistant example application. */
35#error "With ENABLE_EXT_XTAL_INIT defined this device is not supported by porting assistant."
36#endif
37
38/* Test step declarations */
39extern const struct test_step test_step_os_malloc;
40extern const struct test_step test_step_os_realloc;
41extern const struct test_step test_step_os_task_creation;
42extern const struct test_step test_step_os_active_context;
43extern const struct test_step test_step_os_time;
44extern const struct test_step test_step_os_task_preemption;
46extern const struct test_step test_step_mmhal_wlan_init;
49extern const struct test_step test_step_read_chip_id;
50extern const struct test_step test_step_bulk_write_read;
51extern const struct test_step test_step_raw_tput;
56extern const struct test_step test_step_verify_busy_pin;
61static const struct test_step *const test_steps[] = {
65 /* task_creation and active_context tests essential OS pre-conditions and therefore
66 * MUST be tested before other os tests to flag failure early. */
80};
81
84{
86 unsigned no_result;
88 unsigned pass;
90 unsigned fail;
91};
92
100static const char *result_code_to_string(enum test_result result)
101{
102 switch (result)
103 {
104 case TEST_NO_RESULT:
105 return "";
106 case TEST_PASSED:
107 return F_GREEN("PASS");
108 case TEST_SKIPPED:
109 return F_BLUE("SKIP");
110 case TEST_FAILED:
111 return F_RED("FAIL");
112 case TEST_FAILED_NON_CRITICAL:
113 return F_YELLOW("FAIL");
114 }
115 MMOSAL_ASSERT(false);
116}
117
126static void run_test_steps(const struct test_step *const steps[],
127 size_t num_steps,
128 struct test_counters *ctrs)
129{
130 static char log_buf[1024];
131
132 size_t ii;
133 for (ii = 0; ii < num_steps; ii++)
134 {
135 const struct test_step *step = steps[ii];
136 size_t log_buf_len = sizeof(log_buf);
137 log_buf[0] = '\0';
138
139 LOG_PRINTF(F_BOLD("%-60s "), step->description);
140 LOG_FLUSH();
141
142 enum test_result result = step->exec(log_buf, log_buf_len);
143 if (result != TEST_NO_RESULT)
144 {
145 LOG_PRINTF("[ %s ]", result_code_to_string(result));
146 }
147 LOG_WRITE("\n");
148
149 if (log_buf[0] != '\0')
150 {
151 LOG_WRITE("\n");
152 LOG_WRITE(log_buf);
153 }
154 LOG_FLUSH();
155 switch (result)
156 {
157 case TEST_NO_RESULT:
158 ctrs->no_result++;
159 break;
160 case TEST_PASSED:
161 ctrs->pass++;
162 break;
163 case TEST_SKIPPED:
164 break;
165 case TEST_FAILED:
166 ctrs->fail++;
167 break;
168 case TEST_FAILED_NON_CRITICAL:
169 ctrs->fail++;
170 break;
171 }
172
173 if (result == TEST_FAILED)
174 {
175 break;
176 }
177 }
178}
179
184void app_init(void)
185{
186 /* Having deep sleep enabled can complicate debugging. Given the purpose of this applications
187 * is to validate that you can communicate to the MM-Chip it will be disabled by default. */
189
190 struct test_counters ctrs = { 0 };
191 unsigned num_tests = sizeof(test_steps) / sizeof(test_steps[0]);
192
193 char hw_version_string[32] = { 0 };
194
195 bool ok = mmhal_get_hardware_version(hw_version_string, sizeof(hw_version_string));
196 if (!ok)
197 {
198 snprintf(hw_version_string, sizeof(hw_version_string), "%s", "Unknown");
199 }
200
201 LOG_WRITE(F_BOLD("\n\nMM-IoT-SDK Porting Assistant\n"));
202 LOG_WRITE("----------------------------\n");
203 LOG_PRINTF(" HW Version: %s\n", hw_version_string);
204 LOG_PRINTF(" Morselib version: %s\n", MM_VERSION_BUILDID);
205 LOG_WRITE("----------------------------\n\n");
206
207 run_test_steps(test_steps, num_tests, &ctrs);
208
209 LOG_PRINTF("\n\n%u total test steps. %u passed, %u failed, %u no result, %u skipped\n",
210 num_tests,
211 ctrs.pass,
212 ctrs.fail,
213 ctrs.no_result,
214 num_tests - ctrs.no_result - ctrs.pass - ctrs.fail);
215}
bool mmhal_get_hardware_version(char *version_buffer, size_t version_buffer_length)
Reads information that can be used to identify the hardware platform, such as hardware ID and version...
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_core.h:41
#define MMOSAL_ASSERT(expr)
Assert that the given expression evaluates to true and abort execution if not.
Definition: mmosal.h:1006
#define MM_VERSION_BUILDID
Build identifier string.
Definition: mmversion.h:32
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_os_active_context
Test definition.
const struct test_step test_step_verify_busy_pin
Test definition.
const struct test_step test_step_os_task_preemption
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_benchmark_cpu_mem_stack_perf
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.