Inclusion of unit tests

parent ad52d450
...@@ -70,7 +70,7 @@ static void stopHandler(int sign) ...@@ -70,7 +70,7 @@ static void stopHandler(int sign)
running = false; running = false;
} }
#ifndef DOING_UNIT_TESTS
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
// init dictionary only once$ // init dictionary only once$
...@@ -194,3 +194,4 @@ int main(int argc, char **argv) ...@@ -194,3 +194,4 @@ int main(int argc, char **argv)
return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE; return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
} }
#endif
\ No newline at end of file
...@@ -3,7 +3,7 @@ CFLAGS= -l:libopen62541.so -L/usr/local/lib -Wall -Wno-missing-braces -ggdb `pkg ...@@ -3,7 +3,7 @@ CFLAGS= -l:libopen62541.so -L/usr/local/lib -Wall -Wno-missing-braces -ggdb `pkg
LDFLAGS= `pkg-config --libs criterion` -lmbedcrypto -lmbedx509 LDFLAGS= `pkg-config --libs criterion` -lmbedcrypto -lmbedx509
OUT_DIR=build/ OUT_DIR=build/
all: test_common test_modio_i2c test_keep_alive test_keep_alive_publisher all: test_common test_modio_i2c test_keep_alive test_keep_alive_publisher test_keep_alive_subscriber
test_common: test_common.o test_common: test_common.o
@mkdir -p $(OUT_DIR) @mkdir -p $(OUT_DIR)
...@@ -25,12 +25,18 @@ test_keep_alive_publisher: test_keep_alive_publisher.o ...@@ -25,12 +25,18 @@ test_keep_alive_publisher: test_keep_alive_publisher.o
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS) $(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
@mv $@ $(OUT_DIR) @mv $@ $(OUT_DIR)
test_keep_alive_subscriber: test_keep_alive_subscriber.o
@mkdir -p $(OUT_DIR)
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
@mv $@ $(OUT_DIR)
run: all run: all
@${OUT_DIR}/test_common --tap=${OUT_DIR}/test_common.tap @${OUT_DIR}/test_common --tap=${OUT_DIR}/test_common.tap
@${OUT_DIR}/test_modio_i2c --tap=${OUT_DIR}/test_modio_i2c.tap @${OUT_DIR}/test_modio_i2c --tap=${OUT_DIR}/test_modio_i2c.tap
@${OUT_DIR}/test_keep_alive --tap=${OUT_DIR}/test_keep_alive.tap @${OUT_DIR}/test_keep_alive --tap=${OUT_DIR}/test_keep_alive.tap
@${OUT_DIR}/test_keep_alive_publisher --tap=${OUT_DIR}/test_keep_alive_publisher.tap @${OUT_DIR}/test_keep_alive_publisher --tap=${OUT_DIR}/test_keep_alive_publisher.tap
@${OUT_DIR}/test_keep_alive_subscriber --tap=${OUT_DIR}/test_keep_alive_subscriber.tap
clean: clean:
@rm $(OUT_DIR)test_common 2>/dev/null || true @rm $(OUT_DIR)test_common 2>/dev/null || true
...@@ -41,6 +47,8 @@ clean: ...@@ -41,6 +47,8 @@ clean:
@rm $(OUT_DIR)test_keep_alive.tap 2>/dev/null || true @rm $(OUT_DIR)test_keep_alive.tap 2>/dev/null || true
@rm $(OUT_DIR)test_keep_alive_publisher 2>/dev/null || true @rm $(OUT_DIR)test_keep_alive_publisher 2>/dev/null || true
@rm $(OUT_DIR)test_keep_alive_publisher.tap 2>/dev/null || true @rm $(OUT_DIR)test_keep_alive_publisher.tap 2>/dev/null || true
@rm $(OUT_DIR)test_keep_alive_subscriber 2>/dev/null || true
@rm $(OUT_DIR)test_keep_alive_subscriber.tap 2>/dev/null || true
@rm *.o 2>/dev/null || true @rm *.o 2>/dev/null || true
......
/* ================ Includes ===================== */ /* ================ Includes ===================== */
#define DOING_UNIT_TESTS
#include <criterion/criterion.h> #include <criterion/criterion.h>
#include <linux/i2c-dev.h> #include "../../coupler/opc-ua-server/server.c"
#include <open62541/plugin/log_stdout.h>
#include <open62541/server.h>
// #include "../../coupler/opc-ua-server/server.c"
// #include "../../coupler/opc-ua-server/common.h"
// #include "../../coupler/opc-ua-server/mod_io_i2c.h"
// #include "../../coupler/opc-ua-server/keep_alive_publisher.h"
/* ================ Function Tests =============== */ /* ================ Function Tests =============== */
// ############# check heart beats of the server ############## // ############# check heart beats of the server ##############
// Test(keepalivepublisher, callbackTicHeartBeat) { Test(keepalivepublisher, callbackTicHeartBeat) {
// int result = 1; int result = 1;
// callbackTicHeartBeat();
// cr_expect_geq(HEART_BEATS, result); server = UA_Server_new();
// } callbackTicHeartBeat();
UA_Server_delete(server);
cr_expect_geq(HEART_BEATS, result);
}
/* ================ Includes ===================== */
#define DOING_UNIT_TESTS
#include <criterion/criterion.h>
#include "../../coupler/opc-ua-server/server.c"
/* ================ Function Tests =============== */
// ############# check heart beats of the server ##############
Test(keepalivepublisher, callbackTicHeartBeat) {
int result = 0;
server = UA_Server_new();
callbackCheckHeartBeat();
UA_Server_delete(server);
cr_expect_geq(HEART_BEAT_ID_LIST[0], result);
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment