aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2016-03-14 21:04:50 +0100
committerHarald Welte <laforge@gnumonks.org>2016-03-17 16:55:11 +0100
commit676e53446285d1b8f514580fd9485d1f27493c0b (patch)
tree1faea4123fd528d5581397ef80c3403af45f3ea7
parent4acaa13433cc15e4f1d9ee850d78af47419768ab (diff)
sim: Add simplistic unit test for APDU class tables
-rw-r--r--.gitignore1
-rw-r--r--tests/Makefile.am8
-rw-r--r--tests/sim/sim_test.c57
-rw-r--r--tests/sim/sim_test.ok6
-rw-r--r--tests/testsuite.at6
5 files changed, 76 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 89049387..f73a533e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -85,6 +85,7 @@ tests/bitvec/bitvec_test
tests/bits/bitcomp_test
tests/gprs/gprs_test
tests/msgb/msgb_test
+tests/sim/sim_test
utils/osmo-arfcn
utils/osmo-auc-gen
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 571e87b0..03506af3 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -12,7 +12,8 @@ check_PROGRAMS = timer/timer_test sms/sms_test ussd/ussd_test \
loggingrb/loggingrb_test strrb/strrb_test \
vty/vty_test comp128/comp128_test utils/utils_test \
smscb/gsm0341_test stats/stats_test \
- bitvec/bitvec_test msgb/msgb_test bits/bitcomp_test
+ bitvec/bitvec_test msgb/msgb_test bits/bitcomp_test \
+ sim/sim_test
if ENABLE_MSGFILE
check_PROGRAMS += msgfile/msgfile_test
@@ -105,6 +106,8 @@ strrb_strrb_test_LDADD = $(top_builddir)/src/libosmocore.la
vty_vty_test_SOURCES = vty/vty_test.c
vty_vty_test_LDADD = $(top_builddir)/src/vty/libosmovty.la $(top_builddir)/src/libosmocore.la
+sim_sim_test_SOURCES = sim/sim_test.c
+sim_sim_test_LDADD = $(top_builddir)/src/sim/libosmosim.la $(top_builddir)/src/libosmocore.la
# The `:;' works around a Bash 3.2 bug when the output is not writeable.
$(srcdir)/package.m4: $(top_srcdir)/configure.ac
@@ -139,7 +142,8 @@ EXTRA_DIST = testsuite.at $(srcdir)/package.m4 $(TESTSUITE) \
loggingrb/logging_test.err strrb/strrb_test.ok \
vty/vty_test.ok comp128/comp128_test.ok \
utils/utils_test.ok stats/stats_test.ok \
- bitvec/bitvec_test.ok msgb/msgb_test.ok bits/bitcomp_test.ok
+ bitvec/bitvec_test.ok msgb/msgb_test.ok bits/bitcomp_test.ok \
+ sim/sim_test.ok
DISTCLEANFILES = atconfig
diff --git a/tests/sim/sim_test.c b/tests/sim/sim_test.c
new file mode 100644
index 00000000..4710c32e
--- /dev/null
+++ b/tests/sim/sim_test.c
@@ -0,0 +1,57 @@
+/*
+ * (C) 2016 by Harald Welte <laforge@gnumonks.org>
+ * All Rights Reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <osmocom/sim/sim.h>
+#include <osmocom/sim/class_tables.h>
+
+const uint8_t sim_sel_mf[] = { 0xA0, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00 };
+const uint8_t usim_sel_mf[] = { 0x00, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00 };
+const uint8_t uicc_tprof[] = { 0x80, 0x10, 0x00, 0x00, 0x02, 0x01, 0x02 };
+const uint8_t uicc_tprof_wrong_class[] = { 0x00, 0x10, 0x00, 0x00, 0x02, 0x01, 0x02 };
+const uint8_t uicc_read[] = { 0x00, 0xB0, 0x00, 0x00, 0x10 };
+const uint8_t uicc_upd[] = { 0x00, 0xD6, 0x00, 0x00, 0x02, 0x01, 0x02 };
+
+#define APDU_CASE_ASSERT(x, y) \
+ do { \
+ printf("Testing " #x "\n"); \
+ int rc = osim_determine_apdu_case(&osim_uicc_sim_cic_profile, x); \
+ if (rc != y) \
+ printf("%d (actual) != %d (intended)\n", rc, y); \
+ OSMO_ASSERT(rc == y); \
+ } while (0)
+
+static void test_cla_ins_tbl(void)
+{
+ APDU_CASE_ASSERT(sim_sel_mf, 4);
+ APDU_CASE_ASSERT(usim_sel_mf, 4);
+ APDU_CASE_ASSERT(uicc_tprof, 3);
+ APDU_CASE_ASSERT(uicc_tprof_wrong_class, 0);
+ APDU_CASE_ASSERT(uicc_read, 2);
+ APDU_CASE_ASSERT(uicc_upd, 3);
+}
+
+int main(int argc, char **argv)
+{
+ test_cla_ins_tbl();
+}
diff --git a/tests/sim/sim_test.ok b/tests/sim/sim_test.ok
new file mode 100644
index 00000000..7d3f986d
--- /dev/null
+++ b/tests/sim/sim_test.ok
@@ -0,0 +1,6 @@
+Testing sim_sel_mf
+Testing usim_sel_mf
+Testing uicc_tprof
+Testing uicc_tprof_wrong_class
+Testing uicc_read
+Testing uicc_upd
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 3d4d5265..902c1fcc 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -173,6 +173,12 @@ cat $abs_srcdir/gb/bssgp_fc_tests.err > experr
AT_CHECK([$abs_top_srcdir/tests/gb/bssgp_fc_tests.sh $abs_top_builddir/tests/gb], [0], [expout], [experr])
AT_CLEANUP
+AT_SETUP([sim])
+AT_KEYWORDS([sim])
+cat $abs_srcdir/sim/sim_test.ok > expout
+AT_CHECK([$abs_top_builddir/tests/sim/sim_test], [0], [expout], [ignore])
+AT_CLEANUP
+
AT_SETUP([timer])
AT_KEYWORDS([timer])
cat $abs_srcdir/timer/timer_test.ok > expout