Skip to content

Commit

Permalink
Add unit tests for exception handling module
Browse files Browse the repository at this point in the history
Unit tests have been prepared for the following interfaces of the
exception handling module:
  * sol_assert()
  * sol_try()
  * sol_erno_now()

The provision of these unit tests has also resulted in the indirect
testing of the following exception handling and unit testing module
interfaces:
  * SOL_TRY
  * SOL_CATCH
  * sol_throw()
  * sol_tsuite_init2()
  * sol_tsuite_term()
  * sol_tsuite_register()
  * sol_tsuite_exec()
  * sol_tsuite_pass()
  * sol_tsuite_total()

Even so, unit tests for the unit testing module need to be incorporated.
Additionally, CLang has been introduced to the development process; this
will allow continuous integration to be done with CLang in addition to
GCC once llvm-cov is incorporated in the development process.

This commit has been squashed from the 'issue/18' branch.
  • Loading branch information
achakravarti committed Feb 5, 2019
1 parent 0e63d26 commit 866567d
Show file tree
Hide file tree
Showing 8 changed files with 719 additions and 36 deletions.
10 changes: 5 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
# <abhishek@taranjali.org>
#
# License:
# Released under the GNU General Public License version 3 (GPLv3).
# <http://opensource.org/licenses/GPL-3.0>
# See the accompanying README.md file for complete licensing details.
# Released under the GNU General Public License version 3 (GPLv3)
# <http://opensource.org/licenses/GPL-3.0>. See the accompanying LICENSE
# file for complete licensing details.
#
# By continuing to use and/or distribute this file, you acknowledge that
# you have understood these license terms and accept them.
# BY CONTINUING TO USE AND/OR DISTRIBUTE THIS FILE, YOU ACKNOWLEDGE THAT
# YOU HAVE UNDERSTOOD THESE LICENSE TERMS AND ACCEPT THEM.
################################################################################


Expand Down
34 changes: 18 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
# File: sol/Makefile
#
# Description:
# This Makefile is part of the Sol Library. It defines the build rules
# This Makefile is part of the Sol Library. It defines the build rules.
#
# Authors:
# Abhishek Chakravarti <abhishek@taranjali.org>
#
# Copyright:
# (c) 2018, Abhishek Chakravarti.
# (c) 2019, Abhishek Chakravarti.
# <abhishek@taranjali.org>
#
# License:
# Released under the GNU General Public License version 3 (GPLv3).
# <http://opensource.org/licenses/GPL-3.0>
# See the accompanying README.md file for complete licensing details.
# Released under the GNU General Public License version 3 (GPLv3)
# <http://opensource.org/licenses/GPL-3.0>. See the accompanying LICENSE
# file for complete licensing details.
#
# By continuing to use and/or distribute this file, you acknowledge that
# you have understood these license terms and accept them.
# BY CONTINUING TO USE AND/OR DISTRIBUTE THIS FILE, YOU ACKNOWLEDGE THAT
# YOU HAVE UNDERSTOOD THESE LICENSE TERMS AND ACCEPT THEM.
################################################################################


Expand All @@ -34,27 +34,29 @@ DIR_TEST = test


# Set commands
CMD_CC = $(CC)
CMD_SO = $(CC)
CMD_LD = $(CC)
CMD_CC = $(CC)
CMD_SO = $(CC)
CMD_LD = $(CC)
CMD_COV = gcov
CMD_RUN = ./$(OUT_LD)




# Set command options
OPT_CC = -c -fPIC -std=c99 -Wall -g -O0 -coverage
OPT_SO = -shared -g -O0 -coverage
OPT_LD = -std=c99 -Wall -g -O0 -coverage
OPT_CC = -c -fPIC -std=c99 -Wall -g -O0 -coverage
OPT_SO = -shared -g -O0 -coverage
OPT_LD = -std=c99 -Wall -g -O0 -coverage
OPT_COV = -o $(DIR_BLD)




# Set command inputs
INP_SO = $(DIR_BLD)/test.o
INP_LD = $(DIR_TEST)/runner.c
INP_COV = $(DIR_BLD)/runner.gcda $(DIR_BLD)/test.gcda
INP_LD = $(DIR_TEST)/runner.c $(DIR_TEST)/error.t.c
INP_COV = $(DIR_BLD)/test.gcda $(DIR_BLD)/runner.gcda $(DIR_BLD)/error.t.gcda
INP_RUN = $(DIR_BLD)/test.log



Expand Down Expand Up @@ -97,7 +99,7 @@ $(DIR_BLD)/%.o: $(DIR_SRC)/%.c

# Rule to generate integration build
integration: $(OUT_LD)
./$(OUT_LD)
$(CMD_RUN) $(INP_RUN)
mv $(DEP_COV) $(DIR_BLD)
$(CMD_COV) $(OPT_COV) $(INP_COV)
mv $(OUT_COV) $(DIR_BLD)
Expand Down
14 changes: 14 additions & 0 deletions inc/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,20 @@ typedef size_t sol_erno;



/*
* SOL_ERNO_TEST - unit test failure
*
* The SOL_ERNO_TEST symbolic constant indicates that a unit test failed.
* Note that this error code does not indicate an exception with the
* exception handling system, but rather that the condition that a unit
* test is checking has not been fulfilled. This error code is reserved by
* the Sol Library, and should **not** be redefined by client code.
*/
#define SOL_ERNO_TEST ( (sol_erno)0x4 )




/*
* SOL_TRY - start of try block
*
Expand Down
6 changes: 3 additions & 3 deletions inc/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ sol_tsuite_init(sol_tsuite *tsuite);
* - SOL_ERNO_PTR if an invalid pointer is passed as an argument
*/
extern sol_erno
sol_tsuite_init2(sol_tsuite *tsuite,
sol_tlog const *tlog
sol_tsuite_init2(sol_tsuite *tsuite,
sol_tlog *tlog
);


Expand Down Expand Up @@ -221,7 +221,7 @@ sol_tsuite_term(sol_tsuite *tsuite);
*/
extern sol_erno
sol_tsuite_register(sol_tsuite *tsuite,
sol_tcase const *tcase,
sol_tcase *tcase,
char const *desc
);

Expand Down
23 changes: 14 additions & 9 deletions src/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
* tsuite_init() - initialises test suite member fields
*/
static void
tsuite_init(sol_tsuite *tsuite, /* contextual test suite */
sol_tlog const *tlog /* logging callback */
tsuite_init(sol_tsuite *tsuite, /* contextual test suite */
sol_tlog *tlog /* logging callback */
)
{
register int i;
Expand Down Expand Up @@ -85,8 +85,8 @@ sol_tsuite_init(sol_tsuite *tsuite)
* sol_tsuite_init2() - declared in sol/inc/test.h
*/
extern sol_erno
sol_tsuite_init2(sol_tsuite *tsuite,
sol_tlog const *tlog
sol_tsuite_init2(sol_tsuite *tsuite,
sol_tlog *tlog
)
{
SOL_TRY:
Expand All @@ -113,8 +113,9 @@ sol_tsuite_term(sol_tsuite *tsuite)
{
/* reset member fields, including logging callback, if @tsuite
* is valid */
if (tsuite)
if (tsuite) {
tsuite_init (tsuite, 0);
}
}


Expand All @@ -125,7 +126,7 @@ sol_tsuite_term(sol_tsuite *tsuite)
*/
extern sol_erno
sol_tsuite_register(sol_tsuite *tsuite,
sol_tcase const *tcase,
sol_tcase *tcase,
char const *desc
)
{
Expand All @@ -148,7 +149,9 @@ sol_tsuite_register(sol_tsuite *tsuite,
* same as that of the test case */
itr = tsuite->desc [tsuite -> total];
len = SOL_TCASE_MAXDESCLEN;
while (len-- && (*itr++ = *desc++));
while (len-- && (*itr++ = *desc++)) {
;
}

/* update total number of registered test cases */
tsuite->total++;
Expand Down Expand Up @@ -250,11 +253,13 @@ sol_tsuite_exec(sol_tsuite *tsuite)
* logging it if the logging callback is available; update count
* of failed test cases as required */
for (i = 0; i < tsuite->total; i++) {
if ((erno = tsuite->tcase [i] ()))
if ((erno = tsuite->tcase [i] ())) {
tsuite->fail++;
}

if (tsuite->tlog)
if (tsuite->tlog) {
tsuite->tlog (tsuite->desc [i], erno);
}
}

SOL_CATCH:
Expand Down
Loading

0 comments on commit 866567d

Please sign in to comment.