mirror of
https://github.com/esp8266/Arduino.git
synced 2025-12-09 08:01:38 +03:00
add support for environment variables in device tests
Previously device tests included information such as access point SSID/password at compile time. This made it difficult to compile test binaries once and then send them to multiple test runners for execution. This change adds a command to the test library to set environment variable on the target device: “setenv key value”. C library setenv/getenv facility is used to store variables. Test runner, tests, and makefile are updated to use this functionality.
This commit is contained in:
committed by
Ivan Grokhotkov
parent
2315ac20bc
commit
8bd26f2ded
@@ -1,6 +1,8 @@
|
||||
#ifndef BS_PROTOCOL_H
|
||||
#define BS_PROTOCOL_H
|
||||
|
||||
#include "BSArgs.h"
|
||||
|
||||
#define BS_LINE_PREFIX ">>>>>bs_test_"
|
||||
|
||||
namespace bs
|
||||
@@ -44,9 +46,38 @@ void output_menu_end(IO& io)
|
||||
}
|
||||
|
||||
template<typename IO>
|
||||
bool input_menu_choice(IO& io, int& result)
|
||||
void output_setenv_result(IO& io, const char* key, const char* value)
|
||||
{
|
||||
return io.read_int(result);
|
||||
io.printf(BS_LINE_PREFIX "setenv ok key='%s' value='%s'\n", key, value);
|
||||
}
|
||||
|
||||
template<typename IO>
|
||||
bool input_handle(IO& io, char* line_buf, size_t line_buf_size, int& test_num)
|
||||
{
|
||||
int cb_read = io.read_line(line_buf, line_buf_size);
|
||||
if (cb_read == 0 || line_buf[0] == '\n') {
|
||||
return false;
|
||||
}
|
||||
char* argv[4];
|
||||
size_t argc = split_args(line_buf, argv, sizeof(argv)/sizeof(argv[0]));
|
||||
if (argc == 0) {
|
||||
return false;
|
||||
}
|
||||
if (strcmp(argv[0], "setenv") == 0) {
|
||||
if (argc != 3) {
|
||||
return false;
|
||||
}
|
||||
setenv(argv[1], argv[2], 1);
|
||||
output_setenv_result(io, argv[1], argv[2]);
|
||||
test_num = -1;
|
||||
return false; /* we didn't get the test number yet, so return false */
|
||||
}
|
||||
char* endptr;
|
||||
test_num = (int) strtol(argv[0], &endptr, 10);
|
||||
if (endptr != argv[0] + strlen(argv[0])) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // ::protocol
|
||||
|
||||
Reference in New Issue
Block a user