From f30e22bb17b6c97ed4ac850e225bba7b6d8dc159 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 14 Nov 2019 08:36:19 +0100 Subject: [PATCH] initial checkin of CCID tests Change-Id: I35f41cb0097a4408afe7c31f42463baaa47f15bd --- ccid/CCID_Tests.cfg | 20 ++++ ccid/CCID_Tests.default | 8 ++ ccid/CCID_Tests.ttcn | 199 ++++++++++++++++++++++++++++++++++++++++ ccid/gen_links.sh | 21 +++++ ccid/regen_makefile.sh | 9 ++ deps/Makefile | 4 +- 6 files changed, 260 insertions(+), 1 deletion(-) create mode 100644 ccid/CCID_Tests.cfg create mode 100644 ccid/CCID_Tests.default create mode 100644 ccid/CCID_Tests.ttcn create mode 100755 ccid/gen_links.sh create mode 100755 ccid/regen_makefile.sh diff --git a/ccid/CCID_Tests.cfg b/ccid/CCID_Tests.cfg new file mode 100644 index 000000000..de427b2c8 --- /dev/null +++ b/ccid/CCID_Tests.cfg @@ -0,0 +1,20 @@ +[ORDERED_INCLUDE] +# Common configuration, shared between test suites +"../Common.cfg" +# testsuite specific configuration, not expected to change +"./CCID_Tests.default" + +# Local configuration below + +[LOGGING] +ConsoleMask := ERROR | WARNING | TESTCASE | USER; + +[TESTPORT_PARAMETERS] + +[MODULE_PARAMETERS] + + +[MAIN_CONTROLLER] + +[EXECUTE] +CCID_Tests.control diff --git a/ccid/CCID_Tests.default b/ccid/CCID_Tests.default new file mode 100644 index 000000000..f441d6703 --- /dev/null +++ b/ccid/CCID_Tests.default @@ -0,0 +1,8 @@ +[LOGGING] +mtc.FileMask := LOG_ALL | TTCN_DEBUG | TTCN_MATCHING | DEBUG_ENCDEC; + +[TESTPORT_PARAMETERS] + +[MODULE_PARAMETERS] + +[EXECUTE] diff --git a/ccid/CCID_Tests.ttcn b/ccid/CCID_Tests.ttcn new file mode 100644 index 000000000..a985536e2 --- /dev/null +++ b/ccid/CCID_Tests.ttcn @@ -0,0 +1,199 @@ +module CCID_Tests { + +import from General_Types all; +import from Osmocom_Types all; +import from Misc_Helpers all; + +import from USB_PortType all; + +import from CCID_Types all; +import from CCID_Templates all; +import from CCID_Emulation all; + +/* global test component; manages CCID device */ +type component Test_CT { + var CCID_Emulation_CT vc_CCID; + port USB_PT USB; + var Slot_CT vc_SLOT[NR_SLOTS]; +}; + +/* per-slot test component; manages one slot */ +type component Slot_CT { + var uint8_t g_slot_nr; + port CCID_SLOT_PT CCID; + timer g_Tguard := 10.0; +}; + +private const integer NR_SLOTS := 4; + +/*********************************************************************** + * helper infrastructure + ***********************************************************************/ + +type function void_fn() runs on Slot_CT; + +/* altstep running on the per-slot test component */ +private altstep as_Tguard() runs on Slot_CT { + [] g_Tguard.timeout { + Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout"); + } +} + +/* first function inside Slot_CT; wait for CCID_EVENT_UP + call testcase-specific function */ +private function f_handler_init(void_fn fn, integer slot_nr) runs on Slot_CT { + g_slot_nr := slot_nr; + CCID.receive(CCID_Emulation_Event:{up_down:=CCID_EVENT_UP}); + g_Tguard.start; + activate(as_Tguard()); + + fn.apply(); +} + +/* start a single slot handler */ +private function f_start_handler(void_fn fn, integer slot_nr) runs on Test_CT +{ + var Slot_CT vc; + + vc_SLOT[slot_nr] := Slot_CT.create("Slot" & int2str(slot_nr)); + connect(vc_SLOT[slot_nr]:CCID, vc_CCID:SLOT[slot_nr]); + vc_SLOT[slot_nr].start(f_handler_init(fn, slot_nr)); +} + +private function f_wait_handlers_complete() runs on Test_CT { + var integer i; + + for (i := 0; i < NR_SLOTS; i := i+1) { + if (vc_SLOT[i] != null) { + vc_SLOT[i].done; + } + } + setverdict(pass); +} + +private function f_start_and_wait() runs on Test_CT { + /* start CCID_Emulation last, it will trigger all the per-slot components */ + vc_CCID.start(CCID_Emulation.main()); + f_wait_handlers_complete(); +} + +private function f_init() runs on Test_CT { + var integer i; + vc_CCID := CCID_Emulation_CT.create("CCID"); + map(vc_CCID:USB, system:USB); + for (i := 0; i < NR_SLOTS; i := i+1) { + vc_SLOT[i] := null; + } +} + +private function f_power_on(CCID_PowerSelect psel := CCID_PWRSEL_AUTO) runs on Slot_CT { + CCID.send(ts_CCID_IccPowerOn(g_slot_nr, psel)); + CCID.receive(tr_CCID_DataBlock(g_slot_nr)); +} + +private function f_xceive(octetstring tx, template octetstring rx) runs on Slot_CT return octetstring { + var CCID_PDU pdu; + + CCID.send(ts_CCID_XfrBlock(g_slot_nr, tx, 0)); + alt { + [] CCID.receive(tr_CCID_DataBlock(g_slot_nr, ?, rx)) -> value pdu { + return pdu.u.DataBlock.abData; + } + [] CCID.receive(tr_CCID_DataBlock(g_slot_nr, ?, ?)) -> value pdu { + setverdict(fail, "Received unexpected DataBlock ", pdu); + self.stop; + } + [] CCID.receive(CCID_PDU:?) -> value pdu { + setverdict(fail, "Received unexpected CCID ", pdu); + self.stop; + } + } + return ''O; +} + + +/*********************************************************************** + * actual test cases + ***********************************************************************/ + + +/* request 100 times the slot status */ +private function f_TC_getstatus() runs on Slot_CT +{ + var integer i; + for (i := 0; i < 100; i := i+1) { + CCID.send(ts_CCID_GetSlotStatus(g_slot_nr)); + /* it would be fun to simply send more requests here, but the CCID + * spec doesn't permit more than one unresponded command [per slot] */ + alt { + [] CCID.receive(tr_CCID_SlotStatus(g_slot_nr)); + [] CCID.receive { + setverdict(fail, "Unexpected data from device"); + } + } + } + setverdict(pass); +} +testcase TC_get_status() runs on Test_CT +{ + var integer i; + + f_init(); + + for (i := 0; i < NR_SLOTS; i := i+1) { + f_start_handler(refers(f_TC_getstatus), i); + } + + f_start_and_wait(); +} + + +private function f_TC_power_on() runs on Slot_CT +{ + f_power_on(); +} +testcase TC_power_on() runs on Test_CT +{ + var integer i; + + f_init(); + + for (i := 0; i < NR_SLOTS; i := i+1) { + f_start_handler(refers(f_TC_power_on), i); + } + + f_start_and_wait(); +} + +private function f_TC_select_mf() runs on Slot_CT +{ + var integer i; + f_power_on(); + for (i := 0; i < 10000; i := i+1) { + f_xceive('00a40004023f00'O, ?); + } +} +testcase TC_select_mf() runs on Test_CT +{ + var integer i; + + f_init(); + + for (i := 0; i < NR_SLOTS; i := i+1) { + f_start_handler(refers(f_TC_select_mf), i); + } + + f_start_and_wait(); +} + + + +control { + execute( TC_get_status() ); + execute( TC_power_on() ); + execute( TC_select_mf() ); +} + + + + +} diff --git a/ccid/gen_links.sh b/ccid/gen_links.sh new file mode 100755 index 000000000..e53954b65 --- /dev/null +++ b/ccid/gen_links.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +BASEDIR=../deps + +. ../gen_links.sh.inc + +#DIR=$BASEDIR/titan.Libraries.TCCUsefulFunctions/src +#FILES="TCCInterface_Functions.ttcn TCCConversion_Functions.ttcn TCCConversion.cc TCCInterface.cc TCCInterface_ip.h" +#gen_links $DIR $FILES + +DIR=$BASEDIR/titan.TestPorts.USB/src +FILES="USB_PT.cc USB_PT.hh USB_PortType.ttcn USB_PortTypes.ttcn USB_Templates.ttcn USB_Types.ttcn USB_Component.ttcn " +FILES+="CCID_Types.ttcn CCID_Templates.ttcn CCID_Emulation.ttcn " +gen_links $DIR $FILES + +DIR=../library +FILES="Misc_Helpers.ttcn General_Types.ttcn Osmocom_Types.ttcn " +FILES+="Native_Functions.ttcn Native_FunctionDefs.cc " +gen_links $DIR $FILES + +ignore_pp_results diff --git a/ccid/regen_makefile.sh b/ccid/regen_makefile.sh new file mode 100755 index 000000000..215d9c69d --- /dev/null +++ b/ccid/regen_makefile.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +FILES="*.ttcn USB_PT.cc Native_FunctionDefs.cc " + +../regen-makefile.sh CCID_Tests.ttcn $FILES + +#sed -i -e 's/^LINUX_LIBS = -lxml2/LINUX_LIBS = -lxml2 -lusb/' Makefile +sed -i -e '/^LINUX_LIBS/ s/$/ `pkg-config --libs libusb-1.0`/' Makefile +sed -i -e '/^CPPFLAGS/ s/$/ `pkg-config --cflags libusb-1.0`/' Makefile diff --git a/deps/Makefile b/deps/Makefile index 2d8f68715..5d263aa84 100644 --- a/deps/Makefile +++ b/deps/Makefile @@ -67,7 +67,8 @@ OSMOGITHUB_REPOS= titan.TestPorts.SCTPasp \ titan.ProtocolEmulations.M3UA OSMOGIT_REPOS= titan.ProtocolModules.MAP \ - titan.ProtocolModules.BSSMAP + titan.ProtocolModules.BSSMAP \ + titan.TestPorts.USB ALL_REPOS=$(ECLIPSEGIT_REPOS) $(ECLIPSEGIT2_REPOS) $(OSMOGITHUB_REPOS) $(OSMOGIT_REPOS) @@ -121,6 +122,7 @@ titan.TestPorts.TCPasp_commit= R.9.A titan.TestPorts.TELNETasp_commit= R.9.A titan.TestPorts.UDPasp_commit= R.8.A titan.TestPorts.UNIX_DOMAIN_SOCKETasp_commit= R.2.A-4-gbacd73d +titan.TestPorts.USB_commit= master all: $(foreach dir,$(ALL_REPOS),$(dir)/update) clean: $(foreach dir,$(ALL_REPOS),$(dir)/clean)