From 79ba2aefbbc7fcf8f8b60b5efab417e5684b13b6 Mon Sep 17 00:00:00 2001 From: SzuWei Lin Date: Fri, 9 Jun 2017 16:44:23 +0800 Subject: Add stress test case and some debug symbols - A test case run_stress_tests.sh with a larger DTO test case - A flag to test with enabling valgrind - A flag to dump dtb when testing - A flag to disable memory pool machanism Bug: 62474732 Test: tests/run_stress_tests.sh with enabling flags Change-Id: Ibe4c3d1098bc732d21218e1bdc01eed49cf9e440 --- tests/apply_overlay.sh | 20 +++++++++- tests/run_stress_test.sh | 101 +++++++++++++++++++++++++++++++++++++++++++++++ ufdt_node_pool.c | 11 ++++++ 3 files changed, 131 insertions(+), 1 deletion(-) create mode 100755 tests/run_stress_test.sh diff --git a/tests/apply_overlay.sh b/tests/apply_overlay.sh index 55f863c..3da3a64 100755 --- a/tests/apply_overlay.sh +++ b/tests/apply_overlay.sh @@ -15,6 +15,12 @@ PROG_NAME=`basename $0` +# Set to true to get more debug information +DEBUG=false +# Remove the comment to enable valgrind +# Require build with $mmma external/valgrind +#VALGRIND="valgrind --leak-check=yes --show-reachable=yes" + function usage() { echo "Usage:" echo " $PROG_NAME (--fdt|--ufdt) (--remote) " @@ -68,19 +74,27 @@ BASE_DTS_NAME=`basename "$BASE_DTS"` BASE_DTB_NAME="${BASE_DTS_NAME}-base.dtb" BASE_DTB="${TEMP_DIR}/${BASE_DTB_NAME}" dtc -@ -qq -O dtb -o "$BASE_DTB" "$BASE_DTS" +if $DEBUG; then + echo "[base.dts]" + dtc -O dts "$BASE_DTB" +fi # Compile the *-overlay.dts to make *-overlay.dtb OVERLAY_DTS_NAME=`basename "$OVERLAY_DTS"` OVERLAY_DTB_NAME="${OVERLAY_DTS_NAME}-overlay.dtb" OVERLAY_DTB="${TEMP_DIR}/${OVERLAY_DTB_NAME}" dtc -@ -qq -O dtb -o "$OVERLAY_DTB" "$OVERLAY_DTS" +if $DEBUG; then + echo "[overlay.dts]" + dtc -O dts "$OVERLAY_DTB" +fi # Run ufdt_apply_overlay to combine *-base.dtb and *-overlay.dtb # into *-merged.dtb MERGED_DTB_NAME="${BASE_DTS_NAME}-merged.dtb" MERGED_DTB="${TEMP_DIR}/${MERGED_DTB_NAME}" if [ -z "$REMOTE_PATH" ]; then - "$OVERLAY" "$BASE_DTB" "$OVERLAY_DTB" "$MERGED_DTB" + $VALGRIND "$OVERLAY" "$BASE_DTB" "$OVERLAY_DTB" "$MERGED_DTB" else adb push "$BASE_DTB" "$REMOTE_PATH" > /dev/null adb push "$OVERLAY_DTB" "$REMOTE_PATH" > /dev/null @@ -104,3 +118,7 @@ fi # Dump dtc -s -O dts -o "$OUT_DTS" "$MERGED_DTB" +if $DEBUG; then + echo "[merged.dts]" + cat $OUT_DTS +fi diff --git a/tests/run_stress_test.sh b/tests/run_stress_test.sh new file mode 100755 index 0000000..0caf2b4 --- /dev/null +++ b/tests/run_stress_test.sh @@ -0,0 +1,101 @@ +#!/bin/bash +# Copyright (C) 2016 The Android Open Source Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Include some functions from common.sh. +SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" +source ${SCRIPT_DIR}/common.sh + +OUT_DATA_DIR="test_out" + +DEBUG=false + + +apply_overlay() { + local overaly="$1" + local base_dts="$2" + local overlay_dts="$3" + local merged_dts="$4" + + ./apply_overlay.sh "--$overaly" "$base_dts" "$overlay_dts" "$merged_dts" +} + +run_stress_test() { + # see ufdt_gen_test_dts.c for detail + local node_depth="$1" + local node_unused="$2" + local node_count="$3" + local append_count="$4" + local override_count="$5" + + mkdir -p "$OUT_DATA_DIR" >& /dev/null + + # + # Prepare dtb and dtbo files + # + local base_dts="${OUT_DATA_DIR}/base.dts" + echo " Base DT: depth=$node_depth unused=$node_unused nodes=$node_count" + ufdt_gen_test_dts -n $node_count -d $node_depth -u $node_unused \ + -o "$base_dts" + if $DEBUG; then + cat "$base_dts" + fi + + local overlay_dts="${OUT_DATA_DIR}/overlay.dts" + echo " Overlay DT: append=$append_count override=$override_count" + ufdt_gen_test_dts -p -a $append_count -w $override_count \ + -o "$overlay_dts" + if $DEBUG; then + cat "$overlay_dts" + fi + + local merged_dts="${OUT_DATA_DIR}/overlay_merged.dts" + apply_overlay ufdt $base_dts $overlay_dts $merged_dts + + rm -rf "$OUT_DATA_DIR" +} + +main() { + alert "========== Running Stress Tests ==========" + + if [ -z "$ANDROID_BUILD_TOP" ]; then + die "Run envsetup.sh / lunch yet?" + fi + + if ! command_exists ufdt_gen_test_dts || + ! command_exists dtc; then + die "Run mmma $(dirname $SCRIPT_DIR) yet?" + fi + + ( + + # cd to ${SCRIPT_DIR} in a subshell because gen_test.sh uses relative + # paths for dependent files. + cd "${SCRIPT_DIR}" + + # node_depth = 2 + # node_unused = 0 + # node_count = 5000 + # append_count = 2500 + # override_count = 2500 + run_stress_test 2 0 5000 2500 2500 + + ) + + if [ $? -ne 0 ]; then + die "Some test cases failed, please check error message..." + fi +} + +main "$@" diff --git a/ufdt_node_pool.c b/ufdt_node_pool.c index dabb285..9f72b71 100644 --- a/ufdt_node_pool.c +++ b/ufdt_node_pool.c @@ -19,6 +19,9 @@ #include "libufdt_sysdeps.h" #include "ufdt_types.h" +/* Define DEBUG_DISABLE_POOL to use dto_malloc and dto_free directly */ +/* #define DEBUG_DISABLE_POOL */ + #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define UFDT_NODE_POOL_ENTRIES_PER_BLOCK 1024 @@ -171,6 +174,10 @@ static void _ufdt_node_pool_remove_block( } void *ufdt_node_pool_alloc(struct ufdt_node_pool *pool) { +#ifdef DEBUG_DISABLE_POOL + return dto_malloc(UFDT_NODE_POOL_ENTRY_SIZE); +#endif + // return dto_malloc(UFDT_NODE_POOL_ENTRY_SIZE); // If there is no free block, create a new one struct ufdt_node_pool_block_header *block = pool->first_block; @@ -209,6 +216,10 @@ static struct ufdt_node_pool_block_header **_ufdt_node_pool_search_block( } void ufdt_node_pool_free(struct ufdt_node_pool *pool, void *node) { +#ifdef DEBUG_DISABLE_POOL + return dto_free(node); +#endif + struct ufdt_node_pool_block_header **block_ptr = _ufdt_node_pool_search_block(pool, node); if (*block_ptr == NULL) { -- cgit v1.2.3 From 79e48a0a0525c3dc7a58b89789e15aea5f396254 Mon Sep 17 00:00:00 2001 From: SzuWei Lin Date: Fri, 9 Jun 2017 16:36:36 +0800 Subject: Fix memory leak problem in ufdt_node_pool_destruct ufdt_node_pool could delay memory block freeing to enhance performance. The left memory blocks should be freed in ufdt_node_pool_destruct(). The patch fix the problem that a wrong code block to free left memory blocks. Bug: 62474732 Test: tests/run_stress_tests.sh with unmark VALGRIND in apply_overlay.sh Change-Id: I5fd2f51a342501ad5bc27b26d343893a822db6b5 --- ufdt_node_pool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ufdt_node_pool.c b/ufdt_node_pool.c index 9f72b71..8b9c8a9 100644 --- a/ufdt_node_pool.c +++ b/ufdt_node_pool.c @@ -75,7 +75,7 @@ void ufdt_node_pool_destruct(struct ufdt_node_pool *pool) { if (block->alloc_entry_cnt != 0) is_leak = 1; struct ufdt_node_pool_block_header *next_block = block->next_block; - if (!block->first_free_entry) dto_free(block); + dto_free(block); block = next_block; } -- cgit v1.2.3