Skip to content

Commit

Permalink
ci(check): update check_soc_struct_headers script
Browse files Browse the repository at this point in the history
  • Loading branch information
L-KAYA authored and Harshal5 committed Jan 20, 2025
1 parent 5863b66 commit 0cfa866
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .gitlab/ci/pre_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ check_chip_support_components:
expire_in: 1 week
script:
- python tools/ci/check_soc_headers_leak.py
- find ${IDF_PATH}/components/soc/**/include/soc/ -name "*_struct.h" -print0 | xargs -0 -n1 ./tools/ci/check_soc_struct_headers.py
- find ${IDF_PATH}/components/soc/**/include/soc/ ${IDF_PATH}/components/soc/**/register/soc/ -name "*_struct.h" -print0 | xargs -0 -n1 ./tools/ci/check_soc_struct_headers.py
- tools/ci/check_esp_memory_utils_headers.sh

check_esp_err_to_name:
Expand Down
19 changes: 9 additions & 10 deletions tools/ci/check_soc_struct_headers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/usr/bin/env python
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0

# A check script that just works at the time of writing...
#
# also builds a structure tree for further reference
#
# Input file format must be similiar to those headers generated by regtool, or this script makes no sense at all
# Input file format must be similar to those headers generated by regtool, or this script makes no sense at all
#
# Known limitation:
# 1. won't accept /* ... */ /* ... */': badly behavior with multiline comment
Expand All @@ -21,18 +20,18 @@
# 5. typedef volatile struct xxx{}: xxx must exists
#
# Otherwise won't fail but warning

import os
import re
import sys
from typing import Any
from typing import Optional


class MemberField:
member_type = ''
bitfield = None

def __init__(self, m_type: str, m_bits: int=None) -> None:
def __init__(self, m_type: str, m_bits: Optional[int]=None) -> None:
self.member_type = m_type
self.bitfield = m_bits

Expand Down Expand Up @@ -74,7 +73,7 @@ class SoCStructureHeaderChecker:
# named typedef, or named struct/union. referd but will not delete
__temp_ref_types = dict() # type: dict

def __expand_type(self, member_type: str, bitfield: int=None) -> Any:
def __expand_type(self, member_type: str, bitfield: Optional[int]=None) -> Any:
if member_type == 'uint32_t':
return MemberField(member_type, bitfield)
if bitfield is not None:
Expand Down Expand Up @@ -121,15 +120,15 @@ def __getline(self, incomment:bool=False) -> Any:
# skip empty line
return self.__getline()
if rawline.count(';') > 1:
print('\033[0;34mINFO\033[0m: line: {}: possibily multiple expression within same line'.format(self.__linecount))
print('\033[0;34mINFO\033[0m: line: {}: possibly multiple expression within same line'.format(self.__linecount))
print(rawline)
return rawline

def __process_structure(self, name: str, is_typedef: bool, is_volatile: bool) -> Any:
ret_val = 0
# first check for anonymous register structs
if is_typedef and is_volatile and name is None:
print('\033[0;31mERROR\033[0m: line {}: annoymous struct'.format(self.__linecount))
print('\033[0;31mERROR\033[0m: line {}: anonymous struct'.format(self.__linecount))
ret_val = -1
node_tree = dict()
bitcount = 0
Expand Down Expand Up @@ -252,7 +251,7 @@ def __process_union(self, name: str, is_typedef: bool, is_volatile: bool) -> Any
ret_val = 0
# first check for anonymous register structs
if is_typedef and is_volatile and name is None:
print('\033[0;31mERROR\033[0m: line {}: annoymous union'.format(self.__linecount))
print('\033[0;31mERROR\033[0m: line {}: anonymous union'.format(self.__linecount))
ret_val = -1
node_tree = dict() # type: Any
has_struct_count = 0
Expand Down Expand Up @@ -334,7 +333,7 @@ def __process_union(self, name: str, is_typedef: bool, is_volatile: bool) -> Any
node_tree[match_obj.groups()[1]] = member_node
else:
if '*' not in match_obj.groups()[0]:
print('\033[0;31mERROR\033[0m: line {}: unknown type {}'.format(self.__linecount, match_obj.groups()[0]))
print('\033[0;31mWARN\033[0m: line {}: unknown type {}'.format(self.__linecount, match_obj.groups()[0]))
else:
print('\033[0;33mWARN\033[0m: line {}: pointer type {}'.format(self.__linecount, match_obj.groups()[0]))
continue
Expand Down

0 comments on commit 0cfa866

Please sign in to comment.