Skip to content

Commit

Permalink
fix(wifi_remote): Add CI job
Browse files Browse the repository at this point in the history
  • Loading branch information
david-cermak committed Mar 7, 2024
1 parent b93f373 commit e465325
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 52 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/wifi_remote__build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: "esp_wifi_remote: build-tests"

on:
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened, labeled]

jobs:
wifi_remote_api_compat:
if: contains(github.event.pull_request.labels.*.name, 'wifi_remote') || github.event_name == 'push'
name: Check API compatibility of WiFi Remote
strategy:
matrix:
idf_ver: ["latest"]
runs-on: ubuntu-20.04
container: espressif/idf:${{ matrix.idf_ver }}
steps:
- name: Checkout esp-protocols
uses: actions/checkout@v3
- name: Check that headers are the same as generated
shell: bash
run: |
. ${IDF_PATH}/export.sh
cd ./components/esp_wifi_remote/scripts
python parse_header.py
./check_headers.sh
build_wifi_remote:
if: contains(github.event.pull_request.labels.*.name, 'wifi_remote') || github.event_name == 'push'
name: Build WiFi Remote
strategy:
matrix:
idf_ver: ["latest"]
test: [ { app: smoke_test, path: "test/smoke_test" }]
runs-on: ubuntu-20.04
container: espressif/idf:${{ matrix.idf_ver }}
steps:
- name: Checkout esp-protocols
uses: actions/checkout@v3
- name: Build ${{ matrix.test.app }} with IDF-${{ matrix.idf_ver }}
shell: bash
run: |
${IDF_PATH}/install.sh --enable-pytest
. ${IDF_PATH}/export.sh
python ./ci/build_apps.py ./components/esp_wifi_remote/${{matrix.test.path}} -vv --preserve-all
2 changes: 1 addition & 1 deletion components/esp_wifi_remote/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if(NOT CONFIG_ESP_WIFI_ENABLED)
set(src_wifi_is_remote esp_wifi_remote.c)
set(src_wifi_is_remote esp_wifi_remote.c esp_wifi_with_remote.c)
endif()

idf_component_register(INCLUDE_DIRS include
Expand Down
2 changes: 2 additions & 0 deletions components/esp_wifi_remote/esp_wifi_remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ WEAK uint64_t g_wifi_feature_caps =
#endif
0;

#if 0
WEAK esp_err_t esp_wifi_connect(void)
{
return remote_esp_wifi_connect();
Expand Down Expand Up @@ -213,3 +214,4 @@ WEAK esp_err_t esp_wifi_get_protocol(wifi_interface_t ifx, uint8_t *protocol_bit
{
return remote_esp_wifi_get_protocol(ifx, protocol_bitmap);
}
#endif
2 changes: 1 addition & 1 deletion components/esp_wifi_remote/include/esp_wifi_remote_api.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
19 changes: 19 additions & 0 deletions components/esp_wifi_remote/scripts/check_headers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -e

check_files="
include/esp_wifi_remote_api.h
include/esp_wifi_remote_with_hosted.h
esp_wifi_with_remote.c
test/smoke_test/components/esp_hosted/esp_hosted_mock.c
test/smoke_test/components/esp_hosted/include/esp_hosted_mock.h
test/smoke_test/main/all_wifi_calls.c
test/smoke_test/main/all_wifi_remote_calls.c
"

for i in $check_files; do
generated_header="${i##*/}"
current_header="../$i"
echo "Checking $current_header"
diff -I 'FileCopyrightText' $generated_header $current_header
done;
104 changes: 59 additions & 45 deletions components/esp_wifi_remote/scripts/parse_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,44 +62,6 @@ def extract_function_prototypes(header_code, header):
visitor.visit(ast)
return visitor.function_prototypes

# def preprocess_header(header_file):
# with open(header_file, 'r') as file:

# # Parse the preprocessed header file and extract function prototypes
# def extract_function_prototypes(header_code):


# Generate test cases for each function
def generate_test_cases():
test_cases = {}
for func_name, args in function_prototypes.items():
test_args = []
for arg_info in args:
if isinstance(arg_info, c_ast.TypeDecl):
print(arg_info.type.names[0])
arg_name = arg_info.declname
arg_type = 'int' # Default to int type if type is missing
else:
arg_name, arg_type = arg_info
test_args.append((arg_name, generate_test_argument(arg_type)))
test_cases[func_name] = test_args
return test_cases


# Generate test argument based on type
def generate_test_argument(arg_type):
if isinstance(arg_type, c_ast.TypeDecl):
return generate_test_argument(arg_type.type)
elif isinstance(arg_type, c_ast.PtrDecl):
return None # Placeholder for pointer argument handling
elif isinstance(arg_type, c_ast.IdentifierType):
if 'int' in arg_type.names:
return 1 # Example integer argument
elif 'float' in arg_type.names:
return 1.0 # Example float argument
# Add more cases as needed for other data types
return None # Unknown type


def generate_forwarding_c_file(prefix):
with open('forwarding.c', 'w') as file:
Expand Down Expand Up @@ -180,21 +142,47 @@ def get_args(parameters):
return comma_separated_params, comma_separated_names


def get_vars(parameters):
definitions = ''
names = []
for param in parameters:
typename = param.type
if typename == 'void' and param.ptr == 0 and param.name is None:
continue
default_value = '0'
declname = param.name
names.append(f'{declname}')
if param.qual != '':
typename = f'{param.qual} ' + typename
if param.ptr > 0:
declname = '*' * param.ptr + declname
default_value = 'NULL'
if param.array > 0:
declname += f'[{param.array}]'
default_value = '{}'
definitions += f' {typename} {declname} = {default_value};\n'
comma_separated_names = ', '.join(names)
return definitions, comma_separated_names


if __name__ == '__main__':
idf_path = os.getenv('IDF_PATH')
if idf_path is None:
raise RuntimeError("Environment variable 'IDF_PATH' wasn't set.")
header = os.path.join(idf_path, 'components', 'esp_wifi', 'include', 'esp_wifi.h')
function_prototypes = extract_function_prototypes(preprocess(idf_path, header), header)
copyright_header = open('copyright_header.h', 'r').read()

namespace = re.compile(r'^esp_wifi')
with open('esp_wifi_remote_api.h', 'w') as f:
f.write(copyright_header)
for func_name, args in function_prototypes.items():
params, _ = get_args(args[1])
remote_func_name = namespace.sub('esp_wifi_remote', func_name)
f.write(f'{args[0]} {remote_func_name}({params});\n')

with open('esp_wifi_to_remote.c', 'w') as f:
with open('esp_wifi_with_remote.c', 'w') as f:
f.write(copyright_header)
f.write('#include "esp_wifi.h"\n')
f.write('#include "esp_wifi_remote.h"\n\n')
for func_name, args in function_prototypes.items():
Expand All @@ -207,30 +195,56 @@ def get_args(parameters):

with open('esp_hosted_mock.c', 'w') as f:
with open('esp_hosted_mock.h', 'w') as h:
f.write(copyright_header)
h.write(copyright_header)
h.write('\n')
f.write('#include "esp_wifi.h"\n')
f.write('#include "esp_wifi_remote.h"\n\n')
f.write('#include "esp_wifi_remote.h"\n')
for func_name, args in function_prototypes.items():
hosted_func_name = namespace.sub('esp_hosted_wifi', func_name)
params, names = get_args(args[1])
ret_type = args[0]
ret_value = '0' # default return value
if (ret_type == 'esp_err_t'):
ret_value = 'ESP_OK'
f.write(f'{ret_type} {hosted_func_name}({params})\n')
f.write(f'\n{ret_type} {hosted_func_name}({params})\n')
f.write('{\n')
f.write(f' return {ret_value};\n')
f.write('}\n\n')
f.write('}\n')
h.write(f'{ret_type} {hosted_func_name}({params});\n')

with open('esp_wifi_remote_with_hosted.h', 'w') as f:
f.write('#include "esp_hosted_wifi_api.h"\n\n')
f.write(copyright_header)
f.write('#include "esp_hosted_wifi_api.h"\n')
for func_name, args in function_prototypes.items():
remote_func_name = namespace.sub('esp_wifi_remote', func_name)
hosted_func_name = namespace.sub('esp_hosted_wifi', func_name)

params, names = get_args(args[1])
f.write(f'static inline {args[0]} {remote_func_name}({params})\n')
f.write(f'\nstatic inline {args[0]} {remote_func_name}({params})\n')
f.write('{\n')
f.write(f' return {hosted_func_name}({names});\n')
f.write('}\n\n')
f.write('}\n')

with open('all_wifi_calls.c', 'w') as wifi:
with open('all_wifi_remote_calls.c', 'w') as remote:
wifi.write(copyright_header)
remote.write(copyright_header)
wifi.write('#include "esp_wifi.h"\n\n')
remote.write('#include "esp_wifi_remote.h"\n\n')
wifi.write('void run_all_wifi_apis(void)\n{\n')
remote.write('void run_all_wifi_remote_apis(void)\n{\n')
for func_name, args in function_prototypes.items():
remote_func_name = namespace.sub('esp_wifi_remote', func_name)

defs, names = get_vars(args[1])
wifi.write(' {\n')
wifi.write(f'{defs}')
wifi.write(f' {func_name}({names});\n')
wifi.write(' }\n\n')
remote.write(' {\n')
remote.write(f'{defs}')
remote.write(f' {remote_func_name}({names});\n')
remote.write(' }\n\n')
wifi.write('}\n')
remote.write('}\n')
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
* SPDX-License-Identifier: Apache-2.0
*/
#include "esp_wifi.h"
#include "esp_wifi_remote.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
* SPDX-License-Identifier: Apache-2.0
*/

esp_err_t esp_hosted_wifi_init(const wifi_init_config_t *config);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
idf_component_register(SRCS "smoke_test.c"
idf_component_register(SRCS "smoke_test.c" "all_wifi_calls.c" "all_wifi_remote_calls.c"
INCLUDE_DIRS ".")
7 changes: 5 additions & 2 deletions components/esp_wifi_remote/test/smoke_test/main/smoke_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
#include <stdio.h>
#include "esp_wifi_remote.h"

void run_all_wifi_apis(void);
void run_all_wifi_remote_apis(void);

void app_main(void)
{
const wifi_init_config_t config = {};
esp_wifi_remote_init(&config);
run_all_wifi_apis();
run_all_wifi_remote_apis();
}

0 comments on commit e465325

Please sign in to comment.