From a0bc68ac9225511db6cad8e7f8ccf1a3f9bf4974 Mon Sep 17 00:00:00 2001 From: "simon.chupin" Date: Thu, 14 Oct 2021 16:22:27 +0200 Subject: [PATCH] tools: add json schema for idf_size --- tools/test_idf_size/json_validate_test.py | 22 ++++ tools/test_idf_size/size_schema.json | 121 ++++++++++++++++++++++ tools/test_idf_size/test.sh | 8 +- 3 files changed, 147 insertions(+), 4 deletions(-) create mode 100644 tools/test_idf_size/json_validate_test.py create mode 100644 tools/test_idf_size/size_schema.json diff --git a/tools/test_idf_size/json_validate_test.py b/tools/test_idf_size/json_validate_test.py new file mode 100644 index 0000000000..491e3d28e7 --- /dev/null +++ b/tools/test_idf_size/json_validate_test.py @@ -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')) diff --git a/tools/test_idf_size/size_schema.json b/tools/test_idf_size/size_schema.json new file mode 100644 index 0000000000..226b9b6b37 --- /dev/null +++ b/tools/test_idf_size/size_schema.json @@ -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" + } + } + } +} \ No newline at end of file diff --git a/tools/test_idf_size/test.sh b/tools/test_idf_size/test.sh index 516086bd9a..15886666ff 100755 --- a/tools/test_idf_size/test.sh +++ b/tools/test_idf_size/test.sh @@ -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 \