Skip to content

Commit

Permalink
SW-8433: Karl Config File Add CI Test (#109)
Browse files Browse the repository at this point in the history
* SW-7698 karl Config File: Reworked things to make it simpler and easier to maintain. also using the madara global logger for debug output, now even leaner!

* SW-8433: Karl Config File Add CI Test, test script, karl logic and karl config files in this package.

* SW-8433: Karl Config File Add CI Test, test script, karl logic and karl config files in this package, aded to travis.

* SW-8433: Karl Config File Add CI Test, test script, karl logic and karl config files in this package, aded to travis, synced karl.cpp.

* SW-8433: Karl Config File Add CI Test, push/sync.

* SW-8433: Karl Config File Add CI Test, push/sync-1.

* SW-8433: Fix for CI test failure and env var expand for karl config.

* SW-8433: Fix for MAC CI test failure, trial and error, I do not have a MAC-1.

* SW-8433: Fix for MAC CI test failure, trial and error, I do not have a MAC-try2.

* SW-8433: Fix for MAC CI test failure, trial and error, I do not have a MAC-try3.

* SW-8433: Fix for MAC CI test failure. MACOSX Dly load failure.

* SW-8433: Fix for karl config CI failure: Only run for non OSX for now.

* SW-8433: Fix for karl config CI failure: test karl logic file wording change...
  • Loading branch information
sawtoothgeek authored and dskyle committed Oct 12, 2018
1 parent 2590756 commit 88cde94
Show file tree
Hide file tree
Showing 11 changed files with 204 additions and 1 deletion.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ script:
- if [ ! -z $TESTS ]; then $MADARA_ROOT/bin/test_fragmentation ; fi
- if [ ! -z $TESTS ]; then $MADARA_ROOT/bin/test_karl_containers ; fi
- if [ ! -z $TESTS ]; then $MADARA_ROOT/bin/test_karl_exceptions ; fi
- if [ ! -z $TESTS ] && ["$TRAVIS_OS_NAME" != "osx"]; then $MADARA_ROOT/scripts/linux/test_karl_config_files.sh ; fi
- if [ ! -z $TESTS ]; then $MADARA_ROOT/bin/test_kb_destructions ; fi
- if [ ! -z $TESTS ]; then $MADARA_ROOT/bin/test_key_expansion ; fi
- if [ ! -z $TESTS ]; then $MADARA_ROOT/bin/test_packet_scheduler ; fi
Expand Down
4 changes: 4 additions & 0 deletions scripts/linux/test_config_files.karl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test_result += 1;

// return result
test_result
7 changes: 7 additions & 0 deletions scripts/linux/test_config_files_init.karl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// setup test_result (=0 for fail, >=1 for pass)
test_result = 0;

// simple increment
test_result += 1


5 changes: 5 additions & 0 deletions scripts/linux/test_config_files_karl_exception.karl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// this will cause an exception
undef_func(test_result += 1);

// return result
test_result
146 changes: 146 additions & 0 deletions scripts/linux/test_karl_config_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#!/bin/bash
#
# Copyright (c) 2015-2018 Carnegie Mellon University. All Rights Reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following acknowledgments
# and disclaimers.
#
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# 3. The names "Carnegie Mellon University," "SEI" and/or "Software
# Engineering Institute" shall not be used to endorse or promote
# products derived from this software without prior written
# permission. For written permission, please contact
# permission@sei.cmu.edu.
#
# 4. Products derived from this software may not be called "SEI" nor
# may "SEI" appear in their names without prior written permission of
# permission@sei.cmu.edu.
#
# 5. Redistributions of any form whatsoever must retain the following
# acknowledgment:
#
# Copyright 2015 Carnegie Mellon University
#
# This material is based upon work funded and supported by the
# Department of Defense under Contract No. FA8721-05-C-0003 with
# Carnegie Mellon University for the operation of the Software
# Engineering Institute, a federally funded research and development
# center.
#
# Any opinions, findings and conclusions or recommendations expressed
# in this material are those of the author(s) and do not necessarily
# reflect the views of the United States Department of Defense.
#
# NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE
# ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN "AS-IS"
# BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND,
# EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT
# LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY,
# EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE
# MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH
# RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT
# INFRINGEMENT.
#
# This material has been approved for public release and unlimited
# distribution.
#
# DM-0002489
#
# karl configurartion files - tests
# each test loads a config file containing karl interpeter logic too
#

MADARA_FAILS=0
TESTLINE=""

# test simple load of one config file which also points to a karl logic file
echo "Test simple load of one config file which also points to a karl logic file"
$MADARA_ROOT/bin/karl -cf $MADARA_ROOT/tests/settings/karl1.cfg &> $MADARA_ROOT/tests/settings/log1

input="$MADARA_ROOT/tests/settings/log1"
while IFS= read -r line
do
#echo "line: $line endline"
TESTLINE=$line
done < "$input"

if [ "$TESTLINE" != "test_result=2" ] ; then
echo "Test 1: Fail"
((MADARA_FAILS++))
else
echo "Test 1: Pass"
fi

# recursion limit test, should fail
echo "Recursion limit test, fallout at 10"
$MADARA_ROOT/bin/karl -cf $MADARA_ROOT/tests/settings/karl.cfg &> $MADARA_ROOT/tests/settings/log2

TESTLINE=""
input="$MADARA_ROOT/tests/settings/log2"
while IFS= read -r line
do
#echo "line: $line endline"
TESTLINE=$line
done < "$input"

if [ "$TESTLINE" == "test_result=1" ] ; then
echo "Test 2: Fail"
((MADARA_FAILS++))
else
echo "Test 2: Pass"
fi

# test one karl config loading another karl config
echo "Test one karl config loading another karl config"
$MADARA_ROOT/bin/karl -cf $MADARA_ROOT/tests/settings/karl2.cfg &> $MADARA_ROOT/tests/settings/log3

TESTLINE=""
input="$MADARA_ROOT/tests/settings/log3"
while IFS= read -r line
do
#echo "line: $line endline"
TESTLINE=$line
done < "$input"

if [ "$TESTLINE" == "test_result=2" ] ; then
echo "Test 3: Fail"
((MADARA_FAILS++))
else
echo "Test 3: Pass"
fi

# test one karl config loading a karl logic file which contains commands to tripper an exception
echo "Test one karl config loading a karl logic file which contains commands to tripper an exception"
$MADARA_ROOT/bin/karl -cf $MADARA_ROOT/tests/settings/karl4.cfg &> $MADARA_ROOT/tests/settings/log4

TESTLINE=""
input="$MADARA_ROOT/tests/settings/log4"
while IFS= read -r line
do
#echo "line: $line endline"
TESTLINE=$line
done < "$input"

if [ "$TESTLINE" == "test_result=1" ] ; then
echo "Test 4: Fail"
((MADARA_FAILS++))
else
echo "Test 4: Pass"
fi

# echo test result information
echo "MADARA_FAILS=$MADARA_FAILS"

exit $MADARA_FAILS




7 changes: 7 additions & 0 deletions tests/settings/karl.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-l 2
-f ../logfile1.txt
-a
-t 12
-w 2
-cf $(MADARA_ROOT)/tests/settings/karl.cfg
-w 5
10 changes: 10 additions & 0 deletions tests/settings/karl1.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-l 2
-f ../logfile1.txt
-a
-t 12
--wait 1
-0f $(MADARA_ROOT)/scripts/linux/test_config_files_init.karl
--wait 1
-i $(MADARA_ROOT)/scripts/linux/test_config_files.karl
-k

4 changes: 4 additions & 0 deletions tests/settings/karl2.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-t 20
--wait 2
-cf $(MADARA_ROOT)/tests/settings/karl3.cfg
-k
8 changes: 8 additions & 0 deletions tests/settings/karl3.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-l 2
-f $(MADARA_ROOT)/tests/settings/logfile1.txt
-a
-t 12
--wait 1
-0f $(MADARA_ROOT)/scripts/linux/test_config_files_init.karl
-k

10 changes: 10 additions & 0 deletions tests/settings/karl4.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-l 2
-f ../logfile1.txt
-a
-t 12
--wait 1
-0f $(MADARA_ROOT)/scripts/linux/test_config_files_init.karl
--wait 1
-i $(MADARA_ROOT)/scripts/linux/test_config_files_karl_exception.karl
-k

3 changes: 2 additions & 1 deletion tools/karl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,8 @@ bool load_config_file(std::string full_path, size_t recursion_limit)
else
{
param = flag_param.substr(flag_param.find_first_of(" ") + 1,
flag_param.length() - (flag_param.find_first_of(" ") + 1));
flag_param.length() - (flag_param.find_first_of(" ") + 1));
param = madara::utility::expand_envs(param);
}
madara_logger_ptr_log(logger::global_logger.get(), logger::LOG_TRACE,
"Flag: %s, Param: %s\n", flag.c_str(), param.c_str());
Expand Down

0 comments on commit 88cde94

Please sign in to comment.