tools: add json schema for idf_size

This commit is contained in:
simon.chupin 2021-10-14 16:22:27 +02:00
parent fb7f4ed6ab
commit a0bc68ac92
3 changed files with 147 additions and 4 deletions

View File

@ -0,0 +1,22 @@
#!/usr/bin/env python
#
# SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
#
import json
import os
from sys import stdin
try:
import jsonschema
except ImportError:
raise RuntimeError('You need to install jsonschema package to use validate command')
input_json = ''
for line in stdin:
input_json += line
size_json = json.loads(input_json)
with open(os.path.join(os.path.dirname(__file__), 'size_schema.json'), 'r') as schema_file:
schema_json = json.load(schema_file)
jsonschema.validate(size_json, schema_json)
print(input_json.strip('\n'))

View File

@ -0,0 +1,121 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://github.com/espressif/esp-idf/blob/master/tools/size-schema.json",
"type": "object",
"oneOf": [
{
"patternProperties": {
"^dram_(data|bss)$": {
"type": "integer"
},
"^used_(dram|iram)$": {
"type": "integer"
},
"^used_(dram|iram)_ratio$": {
"type": "number"
},
"^available_(dram|iram)$": {
"type": "integer"
},
"^flash_(code|rodata)$": {
"type": "integer"
},
"^total_size$": {
"type": "integer"
}
},
"additionalProperties": false,
"required": [
"dram_data",
"dram_bss",
"used_dram",
"available_dram",
"used_dram_ratio",
"used_iram",
"available_iram",
"used_iram_ratio",
"flash_code",
"flash_rodata",
"total_size"
]
},
{
"patternProperties": {
"(\\.a$|\\.o$|\\.obj$|exe)": {
"$ref": "#/$defs/memory_components"
}
},
"additionalProperties": false
},
{
"patternProperties": {
"(^\\.dram0\\.(bss|data)$)": {
"$ref": "#/$defs/archive_details"
},
"(^\\.flash\\.(rodata|text)$)": {
"$ref": "#/$defs/archive_details"
},
"(^\\.iram0\\.(text|vectors)$)": {
"$ref": "#/$defs/archive_details"
}
},
"additionalProperties": false,
"required": [
".dram0.bss",
".dram0.data",
".flash.rodata",
".flash.text",
".iram0.text",
".iram0.vectors"
]
},
{
"patternProperties": {
"(^diff$|^reference$|^current$)": {
"$ref": "#"
}
},
"additionalProperties": false
}
],
"$defs": {
"memory_components": {
"type": "object",
"properties": {
"bss": {
"type": "integer"
},
"data": {
"type": "integer"
},
"flash_rodata": {
"type": "integer"
},
"flash_text": {
"type": "integer"
},
"iram": {
"type": "integer"
},
"total": {
"type": "integer"
}
},
"additionalProperties": false,
"required": [
"bss",
"data",
"flash_rodata",
"flash_text",
"iram",
"total"
]
},
"archive_details": {
"type": "object",
"additionalProperties": {
"type": "integer"
}
}
}
}

View File

@ -11,10 +11,10 @@
&& echo -e "\n***\nRunning idf_size.py --archive_details..." >> output \
&& coverage run -a $IDF_PATH/tools/idf_size.py --archive_details libdriver.a app.map &>> output \
&& echo -e "\n***\nProducing JSON output..." >> output \
&& coverage run -a $IDF_PATH/tools/idf_size.py --json app.map &>> output \
&& coverage run -a $IDF_PATH/tools/idf_size.py --json --archives app.map &>> output \
&& coverage run -a $IDF_PATH/tools/idf_size.py --json --files app.map &>> output \
&& coverage run -a $IDF_PATH/tools/idf_size.py --json --archive_details libdriver.a app.map &>> output \
&& coverage run -a $IDF_PATH/tools/idf_size.py --json app.map | python $IDF_PATH/tools/test_idf_size/json_validate_test.py &>> output \
&& coverage run -a $IDF_PATH/tools/idf_size.py --json --archives app.map | python $IDF_PATH/tools/test_idf_size/json_validate_test.py &>> output \
&& coverage run -a $IDF_PATH/tools/idf_size.py --json --files app.map | python $IDF_PATH/tools/test_idf_size/json_validate_test.py &>> output \
&& coverage run -a $IDF_PATH/tools/idf_size.py --json --archive_details libdriver.a app.map | python $IDF_PATH/tools/test_idf_size/json_validate_test.py &>> output \
&& echo -e "\n***\nProducing JSON file output..." >> output \
&& coverage run -a $IDF_PATH/tools/idf_size.py --json --output-file output.json app.map &>> output \
&& echo -e "\n***\nProducing text file output..." >> output \