Skip to content
Snippets Groups Projects
Commit c641dbad authored by burneykb's avatar burneykb
Browse files
parents f1901a3e ceb4b923
No related branches found
No related tags found
No related merge requests found
Showing with 12559 additions and 74 deletions
build:
stage: build
script:
- echo "It works."
# run tests using the binary built before
test:
stage: test
script:
- bash test-ci.sh
[![build status](https://git.ece.iastate.edu/danc/MicroCART_17-18/badges/master/build.svg)](https://git.ece.iastate.edu/danc/MicroCART_17-18/commits/master)
Repository for 2016-2017 MicroCART project.
% Model Parameters
m = 1.19; % Quadrotor + battery mass
g = 9.81; % Acceleration of gravity
Jxx = 0.0218; % Quadrotor and battery motor of inertia around bx (pitch)
Jyy = 0.0277; % Quadrotor and battery motor of inertia around by (roll)
%Jxx = 0.0218; % Quadrotor and battery motor of inertia around bx (pitch)
%Jyy = 0.0277; % Quadrotor and battery motor of inertia around by (roll)
Jxx = 0.0277;
Jyy = 0.0218;
Jzz = 0.0332; % Quadrotor and battery motor of inertia around bz (yaw)
Jreq = 4.2012e-05; % Rotor and motor moment of inertia around axis of rotation
Kt = 8.6519e-6; % Rotor thrust constant
......
No preview for this file type
This diff is collapsed.
......@@ -169,10 +169,11 @@ struct MessageType MessageTypes[MAX_TYPE_ID] =
int findCommand(char * str)
{
for (int i = 0; i < MAX_TYPE_ID; i++) {
int i;
for (i = 0; i < MAX_TYPE_ID; i++) {
if (strcmp(str, MessageTypes[i].cmdText) == 0) {
return i;
}
}
return -1;
}
\ No newline at end of file
}
example
test.o
\ No newline at end of file
test.o: test.c
gcc -c test.c
example: example.c test.c test.h
gcc -g -o example example.c test.c test.h
.PHONY: clean
clean:
rm example test.o
Basic Testing Suite in C
----
This test suite helps you run tests. It handles the result of every test
whether it be a success, failure, or segfault, and keeps running until
all tests have been executed. It then gives a summary of the test results.
To use, just write your tests using functions that return `int`s to indicate
failure. 1 means failure. 0 means success.
Then in your main function for your tests, pass these functions to the `test()`
function along with a name you want included in the test report.
```c
int main() {
test(test_func, "this test will pass!");
test(another_func, "this one might fail...");
...
```
Then at the end of your main function, call the `test_summary()` function, and
return its return value from your main function.
```c
int main() {
...
return test_summary();
}
```
An `example.c` file is included for reference.
\ No newline at end of file
#include <stdio.h>
#include "test.h"
int test1() {
puts("hi world.");
return 0;
}
int test2() {
return 1;
}
int test3() {
int *bad = NULL;
int x = *bad;
return 0;
}
int main() {
test(test1, "print hello world");
test(test2, "just fail");
test(test3, "survive segfault");
return test_summary();
}
#include "test.h"
static int num_tests = 0;
static struct Test tests[128];
static int longest_test_name = 0;
void test(int (*function)(), char *test_name) {
int test_name_length = strlen(test_name);
if (test_name_length > longest_test_name) {
longest_test_name = test_name_length;
}
pid_t pid = fork();
if (pid == 0) {
// test process
int exit_status = function();
exit(exit_status);
} else {
int status;
waitpid(pid, &status, 0);
struct Test test;
strcpy(test.name, test_name);
if (WIFEXITED(status)) {
int exit_status = WEXITSTATUS(status);
if (exit_status == 0) {
test.failed = 0;
strcpy(test.result_msg, "passed");
} else {
test.failed = 1;
strcpy(test.result_msg, "FAILED");
}
} else if (WIFSIGNALED(status)) {
test.failed = 1;
strcpy(test.result_msg, "ERROR!");
}
tests[num_tests++] = test;
}
}
int test_summary() {
unsigned char at_least_one_test_failed = 0;
int num_failed = 0;
puts("---------------------------------");
puts("Test results:");
puts("");
int i = 0;
for (i = 0; i < num_tests; i += 1) {
printf("#%3d: %-*s (%s)\n", i + 1, longest_test_name, tests[i].name, tests[i].result_msg);
num_failed += tests[i].failed;
at_least_one_test_failed |= tests[i].failed;
}
puts("");
printf("Total: %3d of %-3d tests passed\n", num_tests - num_failed, num_tests);
puts("---------------------------------");
num_tests = 0;
longest_test_name = 0;
return at_least_one_test_failed;
}
#ifndef TEST_H
#define TEST_H
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
struct Test {
char name[64];
char result_msg[32];
unsigned char failed;
};
void test(int (*)(), char *);
int test_summary();
#endif
uart_buff.c
uart_buff.h
test
\ No newline at end of file
test_uart_buff
\ No newline at end of file
.PHONY: test
test:
cp ../src/uart_buff.c ../src/uart_buff.h ./
gcc -g -o test test_uart_buff.c uart_buff.c
# QUAD_ROOT is obtained from environment
SRC = $(QUAD_ROOT)/sw/modular_quad_pid/src
LIB = $(QUAD_ROOT)/lib/test
test_uart_buff: test_uart_buff.c
gcc -o test_uart_buff -I. -I$(SRC) -I$(LIB) $(LIB)/test.o test_uart_buff.c $(SRC)/uart_buff.c
.PHONY: clean
clean:
rm *.o rm *.gch
rm test_uart_buff
......@@ -2,39 +2,7 @@
#include "uart_buff.h"
#include <math.h>
#include <string.h>
int main() {
int failed = 0;
failed += test_empty_when_empty();
failed += test_empty_after_receiving_some_data();
failed += test_full_is_false_at_start();
failed += test_full_after_receiving_some_data();
failed += test_packet_get_u8();
failed += test_packet_get_u8_with_offset();
failed += test_packet_get_u16();
failed += test_packet_get_u16_with_offset();
failed += test_packet_get_u16_wrapped();
failed += test_packet_get_u32();
failed += test_packet_get_u32_with_offset();
failed += test_packet_get_u32_wrapped_1_4();
failed += test_packet_get_u32_wrapped_2_4();
failed += test_packet_get_u32_wrapped_3_4();
failed += test_packet_get_float();
failed += test_packet_get_float_with_offset();
failed += test_buffer_size_after_VRPN_packet();
failed += test_buffer_size_empty();
failed += test_buffer_size_after_garbage_data();
failed += test_buffer_size_after_garbage_data_scanned();
failed += test_packet_ready_at_start();
failed += test_packet_ready_after_receiving_packet();
failed += test_packet_ready_after_consuming_packet();
failed += test_size_when_data_lenth_too_large();
failed += test_get_raw();
printf("Total tests failed: %d\n", failed);
return 0;
}
#include "test.h"
int float_equals(float x1, float x2) {
return fabs(x1 - x2) < 10e-5;
......@@ -69,12 +37,12 @@ void add_packet(u16 type, unsigned short id, unsigned short length, unsigned cha
void add_VRPN_packet() {
float arr[6] = {1.0, 1.2, 1.4, -1.5, -0.5, -1.1};
unsigned char *data = (unsigned char *) &arr;
add_packet(4, 0, 0, 24, data);
add_packet(4, 0, 24, data);
}
void add_basic_packet() {
unsigned char data[6] = {0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
add_packet(4, 0, 0, 6, data);
add_packet(4, 0, 6, data);
}
void add_garbage_data() {
......@@ -104,7 +72,6 @@ int test_empty_when_empty() {
int exp = 1;
int act = uart_buff_empty();
int success = exp == act;
print_test_result(success, (float) exp, (float) act);
return !success;
}
......@@ -114,7 +81,6 @@ int test_empty_after_receiving_some_data() {
int exp = 0;
int act = uart_buff_empty();
int success = exp == act;
print_test_result(success, (float) exp, (float) act);
return !success;
}
......@@ -123,7 +89,6 @@ int test_full_is_false_at_start() {
int exp = 0;
int act = uart_buff_full();
int success = exp == act;
print_test_result(success, (float) exp, (float) act);
return !success;
}
......@@ -133,7 +98,6 @@ int test_full_after_receiving_some_data() {
int exp = 0;
int act = uart_buff_full();
int success = exp == act;
print_test_result(success, (float) exp, (float) act);
return !success;
}
......@@ -142,7 +106,6 @@ int test_buffer_size_empty() {
int exp = 0;
int act = uart_buff_size();
int success = exp == act;
print_test_result(success, (float) exp, (float) act);
return !success;
}
......@@ -152,7 +115,6 @@ int test_buffer_size_after_garbage_data() {
int exp = 32;
int act = uart_buff_size();
int success = exp == act;
print_test_result(success, (float) exp, (float) act);
return !success;
}
......@@ -163,7 +125,6 @@ int test_buffer_size_after_garbage_data_scanned() {
int exp = 0;
int act = uart_buff_size();
int success = exp == act;
print_test_result(success, (float) exp, (float) act);
return !success;
}
......@@ -173,7 +134,6 @@ int test_buffer_size_after_VRPN_packet() {
int exp = 32;
int act = uart_buff_size();
int success = exp == act;
print_test_result(success, (float) exp, (float) act);
return !success;
}
......@@ -183,7 +143,6 @@ int test_packet_get_u8() {
int exp = 0xAA;
int act = uart_buff_data_get_u8(0);
int success = exp == act;
print_test_result(success, (float) exp, (float) act);
return !success;
}
......@@ -193,7 +152,6 @@ int test_packet_get_u8_with_offset() {
int exp = 0xBB;
int act = uart_buff_data_get_u8(1);
int success = exp == act;
print_test_result(success, (float) exp, (float) act);
return !success;
}
......@@ -203,7 +161,6 @@ int test_packet_get_u16() {
int exp = 0xBBAA;
int act = uart_buff_data_get_u16(0);
int success = exp == act;
print_test_result(success, (float) exp, (float) act);
return !success;
}
......@@ -213,7 +170,6 @@ int test_packet_get_u16_with_offset() {
int exp = 0xDDCC;
int act = uart_buff_data_get_u16(2);
int success = exp == act;
print_test_result(success, (float) exp, (float) act);
return !success;
}
......@@ -227,7 +183,6 @@ int test_packet_get_u16_wrapped() {
int exp = 0xBBAA;
int act = uart_buff_data_get_u16(0);
int success = exp == act;
print_test_result(success, (float) exp, (float) act);
return !success;
}
......@@ -237,7 +192,6 @@ int test_packet_get_u32() {
unsigned int exp = 0xDDCCBBAA;
unsigned int act = uart_buff_data_get_u32(0);
int success = exp == act;
print_test_result(success, (float) exp, (float) act);
return !success;
}
......@@ -247,7 +201,6 @@ int test_packet_get_u32_with_offset() {
unsigned int exp = 0xFFEEDDCC;
unsigned int act = uart_buff_data_get_u32(2);
int success = exp == act;
print_test_result(success, (float) exp, (float) act);
return !success;
}
......@@ -261,7 +214,6 @@ int test_packet_get_u32_wrapped_1_4() {
int exp = 0xDDCCBBAA;
int act = uart_buff_data_get_u32(0);
int success = exp == act;
print_test_result(success, (float) exp, (float) act);
return !success;
}
......@@ -275,7 +227,6 @@ int test_packet_get_u32_wrapped_2_4() {
int exp = 0xDDCCBBAA;
int act = uart_buff_data_get_u32(0);
int success = exp == act;
print_test_result(success, (float) exp, (float) act);
return !success;
}
......@@ -289,7 +240,6 @@ int test_packet_get_u32_wrapped_3_4() {
int exp = 0xDDCCBBAA;
int act = uart_buff_data_get_u32(0);
int success = exp == act;
print_test_result(success, (float) exp, (float) act);
return !success;
}
......@@ -300,7 +250,6 @@ int test_packet_get_float() {
float exp = 1.0;
float act = uart_buff_data_get_float(0);
int success = float_equals(exp, act);
print_test_result(success, exp, act);
return !success;
}
......@@ -310,7 +259,6 @@ int test_packet_get_float_with_offset() {
float exp = 1.2;
float act = uart_buff_data_get_float(4);
int success = float_equals(exp, act);
print_test_result(success, exp, act);
return !success;
}
......@@ -319,7 +267,6 @@ int test_packet_ready_at_start() {
int exp = 0;
int act = uart_buff_packet_ready();
int success = act == exp;
print_test_result(success, exp, act);
return !success;
}
......@@ -329,7 +276,6 @@ int test_packet_ready_after_receiving_packet() {
int exp = 1;
int act = uart_buff_packet_ready();
int success = act == exp;
print_test_result(success, exp, act);
return !success;
}
......@@ -340,19 +286,17 @@ int test_packet_ready_after_consuming_packet() {
int exp = 0;
int act = uart_buff_packet_ready();
int success = act == exp;
print_test_result(success, exp, act);
return !success;
}
int test_size_when_data_lenth_too_large() {
uart_buff_reset();
unsigned char data[UART_MAX_PACKET_SIZE + 1];
add_packet(4, 0, 0, UART_MAX_PACKET_SIZE + 1, data);
add_packet(4, 0, UART_MAX_PACKET_SIZE + 1, data);
uart_buff_packet_ready();
int exp = 0;
int act = uart_buff_size();
int success = act == exp;
print_test_result(success, exp, act);
return !success;
}
......@@ -368,10 +312,37 @@ int test_get_raw() {
for (i = 0; i < length; i += 1) {
success = success && (exp[i] == act[i]);
if (!success) {
printf("FAILED");
break;
}
}
if (success) printf("passed\n");
return !success;
}
int main() {
test(test_empty_when_empty, "test empty when empty");
test(test_empty_after_receiving_some_data, "test empty after recieving soem data");
test(test_full_is_false_at_start, "test full is false at start");
test(test_full_after_receiving_some_data, "test full after receiving some data");
test(test_packet_get_u8, "test packet get u8");
test(test_packet_get_u8_with_offset, "test packet get u8 with offset");
test(test_packet_get_u16, "test packet get u16");
test(test_packet_get_u16_with_offset, "test packet get u16 wrapped");
test(test_packet_get_u16_wrapped, "test packet get u16 wrapped");
test(test_packet_get_u32, "test packet get u32");
test(test_packet_get_u32_with_offset, "test packet get u32 with offset");
test(test_packet_get_u32_wrapped_1_4, "test packet get u32 wrapped 1/4");
test(test_packet_get_u32_wrapped_2_4, "test packet get u32 warpped 2/4");
test(test_packet_get_u32_wrapped_3_4, "test packet get u32 wrapped 3/4");
test(test_packet_get_float, "test packet get u32 wrapped 3/4");
test(test_packet_get_float_with_offset, "test packet get float with offset");
test(test_buffer_size_after_VRPN_packet, "test buffer size after VRPN packet");
test(test_buffer_size_empty, "test buffer size empty");
test(test_buffer_size_after_garbage_data, "test buffer size after garbage data");
test(test_buffer_size_after_garbage_data_scanned, "test buffer size after garbage data scanned");
test(test_packet_ready_at_start, "test packet ready at start");
test(test_packet_ready_after_receiving_packet, "test packet ready after receiving packet");
test(test_packet_ready_after_consuming_packet, "test packet ready after consuming packet");
test(test_size_when_data_lenth_too_large, "test size when data length too large");
return test_summary();
}
#!/bin/bash
QUAD_ROOT=$PROJECT_ROOT/quad
export QUAD_ROOT
cd $QUAD_ROOT/lib/test
make || exit 1
cd $QUAD_ROOT/sw/modular_quad_pid/test
make || exit 1
./test_uart_buff || exit 1
#!/bin/bash
PROJECT_ROOT=$(pwd)
export PROJECT_ROOT
# Quad
bash quad/test-ci.sh || exit 1
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment