audk/AppPkg/Applications/OrderedCollectionTest/gentest.sh

87 lines
2.1 KiB
Bash
Raw Normal View History

AppPkg: introduce OrderedCollectionTest In this patch a small application is added to AppPkg, with the following two goals: - demonstrate how to use OrderedCollectionLib, - allow users to test and "fuzz" BaseOrderedCollectionRedBlackTreeLib in particular, entering API "commands" interactively, or providing them from a script file. A shell script is included that generates such an API command script. Speaking about BaseOrderedCollectionRedBlackTreeLib specifically, OrderedCollectionTest validates the internal red-black properties of the tree after each read-write operation by setting the PcdValidateOrderedCollection feature flag to TRUE. The OrderedCollectionTest application's debugging environment is strictly specified in the DSC file, because OrderedCollectionTest is entirely useless for unit testing without full ASSERT() enablement. The OrderedCollectionTest application deliberately doesn't follow the edk2 coding style in the following: - const vs. CONST, - void vs. VOID, - assert() vs. ASSERT(), - calloc() and free() vs. AllocateZeroPool() and FreePool(), - integer types. This is because OrderedCollectionTest is a standard C application, not a UEFI application per se. In particular it relies on stdio. INTN, EFIAPI and CONST VOID are used only in two places, where we provide the comparator callbacks to OrderedCollectionLib. Proper range checking is ensured for integers. The application takes command input from stdin or a file (if the user requests it), sends command output to stdout or a file (if the user requests it), prints debug output to the console (as other AppPkg applications do when debugging is enabled for them), and prints diagnostics to stderr (like well behaved standard C programs should). Input/output selection is implemented manually because the old shell doesn't support input redirection at all, and because the new shell's input redirection does not co-operate with fgets() for the time being. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Reviewed-by: Michael Kinney <michael.d.kinney@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15792 6f19259b-4bc3-4df7-8a09-765794883524
2014-08-12 09:29:17 +02:00
## @file
# Small test script generator for OrderedCollectionTest.
#
# Usage:
# - generate script: sh gentest.sh >input.txt
# - run script with tester: OrderedCollectionTest -i input.txt -o output.txt
#
# Copyright (C) 2014, Red Hat, Inc.
#
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
# distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR
# IMPLIED.
##
set -e -u -C
RANGE_START=0
RANGE_STOP=9999
gen_rnd_insert()
{
shuf --input-range=$RANGE_START-$RANGE_STOP | sed 's/^/insert /'
}
gen_rnd_delete()
{
shuf --input-range=$RANGE_START-$RANGE_STOP | sed 's/^/delete /'
}
gen_mon_inc_insert()
{
seq $RANGE_START $RANGE_STOP | sed 's/^/insert /'
}
gen_mon_inc_delete()
{
seq $RANGE_START $RANGE_STOP | sed 's/^/delete /'
}
gen_mon_dec_delete()
{
seq $RANGE_START $RANGE_STOP | tac | sed 's/^/delete /'
}
{
echo '# populate the tree in random order and empty it iterating forward'
gen_rnd_insert
echo forward-empty
echo
echo '# populate the tree in random order and empty it iterating backward'
gen_rnd_insert
echo backward-empty
echo
echo '# populate the tree in random order, list it in increasing and'
echo '# decreasing order, then empty it in random order'
gen_rnd_insert
echo forward-list
echo backward-list
gen_rnd_delete
echo
echo '# populate the tree in monotonically increasing order, then undo it'
echo '# piecewise in the same order'
gen_mon_inc_insert
gen_mon_inc_delete
echo
echo '# populate the tree in monotonically increasing order, then undo it'
echo '# piecewise in reverse order'
gen_mon_inc_insert
gen_mon_dec_delete
echo
echo '# populate the tree randomly, trigger a run of collisions, then exit'
echo '# and let CmdForwardEmpty() empty the tree'
gen_rnd_insert
gen_mon_inc_insert
} \
| unix2dos