Skip to content

Commit

Permalink
Included live test in gtest, discovered bug, see issue #5
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceShawn committed Jun 9, 2014
1 parent b09742f commit 5099620
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 32 deletions.
2 changes: 1 addition & 1 deletion C/inc/NamedPipe.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class NamedPipe{
bool Exist();
int ReadFromPipe(char* buffer, int buf_size); // Return value : On success, buffer is returned. On failure, NULL is returned.
int WriteToPipe(const void* data, int size); // Return value : On success, the number of bytes written. On failure, negative value.
bool ensure_open(char mode);
bool Open(char mode);
void closePipe();
};
#endif
8 changes: 5 additions & 3 deletions C/inc/Net2Com.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ typedef enum {

class Net2Com{
private :
const static int NULL_CHAR_LENGTH = 1;
static const int NULL_CHAR_LENGTH = 1;
static const int NUMBER_OF_PIPES = 4;
static const char* pipe_str[];

Expand All @@ -21,9 +21,11 @@ class Net2Com{
NamedPipe* dataPipe_r;
NamedPipe* infoPipe_w;
NamedPipe* infoPipe_r;

public :
Net2Com(pipe_num_t dataw, pipe_num_t datar, pipe_num_t infow, pipe_num_t infor); // ORDER : DATA_WRITE, DATA_READ, INFO_WRITE, INFO_READ
// ORDER : DATA_WRITE, DATA_READ, INFO_WRITE, INFO_READ
Net2Com(pipe_num_t dataw, pipe_num_t datar, pipe_num_t infow, pipe_num_t infor);

~Net2Com();
int WriteToDataPipe(const char* str);
int WriteToDataPipe(unsigned char);
Expand Down
2 changes: 1 addition & 1 deletion C/inc/shakespeare.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Shakespeare

char *get_custom_time(string format);

void log(FILE* lf, Priority ePriority, string process, string msg);
int log(FILE* lf, Priority ePriority, string process, string msg);

int file_size_limit_reached(char *filepath, size_t write_size);

Expand Down
28 changes: 14 additions & 14 deletions C/src/SC_he100.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,9 @@ HE100_write(int fdin, unsigned char *bytes, size_t size)
int write_return = 1;
fflush( NULL ); fsync(fdin); // TODO fdin, is a tty device, ineffective?
// Issue a read to check for ACK/NOACK
if ( HE100_read(fdin, 2) > 0 ) {
write_return = 0;
}
// Check if number of bytes written is greater than zero
if (w>0) {
write_return = 0;
if ( ( HE100_read(fdin, 2) == 0 ) && w>0 ) {
write_return = 0;
}
return write_return;
}
Expand Down Expand Up @@ -432,7 +429,7 @@ HE100_read (int fdin, time_t timeout)
unsigned char buffer[1];
unsigned char response[255];
int i=0;
int r=0; // return value for HE100_read
int r=1; // return value for HE100_read
int breakcond=255;
timer_t read_timer = timer_get();
timer_start(&read_timer,timeout,0);
Expand All @@ -445,13 +442,15 @@ HE100_read (int fdin, time_t timeout)
struct pollfd fds;
fds.fd = fdin;
fds.events = POLLIN;

if (fdin==0) return 1;

while (!timer_complete(&read_timer))
{
if ( ( ret_value = poll(&fds, 1, 5) ) /* TODO not nice, be explicit */ ) // if a byte is read
{
read(fdin, &buffer, 1);

read(fdin, &buffer, 1);
HE100_dumpHex(stdout,buffer,1);
// set break condition based on incoming byte pattern
if ( i==4 && (buffer[0] == 0x0A || buffer[0] == 0xFF ) ) // getting an ack
{
Expand Down Expand Up @@ -479,18 +478,19 @@ HE100_read (int fdin, time_t timeout)

if (i==breakcond)
{
printf("Hit Break Condition");
if (i>0) // we have a message to validate
{
int SVR_result = HE100_storeValidResponse(response, breakcond);
int SVR_result = HE100_storeValidResponse(response, breakcond);
if ( SVR_result == 0 )
{
fprintf(stdout, "\r\n VALID MESSAGE!\r\n");
r = 1; // we got a frame, time to ack! // TODO change to exit status
r = 0; // we got a frame, time to ack!
}
else if (SVR_result == 7) {
fprintf(stderr, "\r\n Memory allocation problem!\r\n");
else if (SVR_result == 7) {
fprintf(stderr, "\r\n Memory allocation problem!\r\n");
r=-1;
}
}
else
{
fprintf(stderr, "\r\n Invalid data!\r\n");
Expand All @@ -514,7 +514,7 @@ HE100_read (int fdin, time_t timeout)
else if (ret_value == -1)
{
// bad or no read
printf("Oh dear, something went wrong with select()! %s\n", strerror(errno));
printf("Oh dear, something went wrong with select()! %s\n", strerror(errno));
r = -1;
}
}
Expand Down
8 changes: 7 additions & 1 deletion C/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ CXXFLAGS += -g -Wall -Wextra -pthread

# All tests produced by this Makefile. Remember to add new tests you
# created to the list.
TESTS = he100_lib_test
TESTS = he100_lib_test he100_live_radio_test

# All Google Test headers. Usually you shouldn't change this
# definition.
Expand Down Expand Up @@ -96,3 +96,9 @@ he100_lib_test : he100_lib_test.o NamedPipe.o fletcher.o timer.o shakespeare.o S

he100_lib_test.o : $(USER_DIR)/test/he100_lib_test.cpp $(USER_DIR)/inc/SC_he100.h $(GTEST_HEADERS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/test/he100_lib_test.cpp

he100_live_radio_test : he100_live_radio_test.o NamedPipe.o fletcher.o timer.o shakespeare.o SC_he100.o gtest_main.a
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -lpthread $^ -o $@ -lrt

he100_live_radio_test.o : $(USER_DIR)/test/he100_live_radio_test.cpp $(USER_DIR)/inc/SC_he100.h $(GTEST_HEADERS)
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $(USER_DIR)/test/he100_live_radio_test.cpp
Binary file modified C/test/he100_lib_test
Binary file not shown.
Binary file added C/test/he100_live_radio_test
Binary file not shown.
27 changes: 15 additions & 12 deletions C/test/he100_live_radio_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
class Helium_100_Live_Radio_Test : public ::testing::Test
{
protected:
virtual void SetUp() { }

const static int fdin = 1; // fake file descriptor to simulate HE100
virtual void SetUp() {
}
int fdin = HE100_openPort();
virtual void TearDown() {
HE100_closePort(fdin);
}
//if (fdin==0) exit(EXIT_FAILURE);
size_t z; // assert loop index
};

Expand Down Expand Up @@ -57,18 +61,16 @@ TEST_F(Helium_100_Live_Radio_Test, NOOP)
// Test transmitData
TEST_F(Helium_100_Live_Radio_Test, TransmitData)
{
unsigned char * payload = {0x48,0x65,0x6c,0x6c,0x6f};
unsigned char payload[5] = {0x48,0x65,0x6c,0x6c,0x6f};
int transmit_result = HE100_transmitData(fdin,payload,5);

ASSERT_EQ(
0,
noop_result
transmit_result
);
// TODO READ THE ACTUAL BYTE SEQUENCE RETURNED
}



// Test setBeaconInterval
TEST_F(Helium_100_Live_Radio_Test, SetBeaconInterval)
{
Expand All @@ -84,7 +86,8 @@ TEST_F(Helium_100_Live_Radio_Test, SetBeaconInterval)
// Test setBeaconMessage
TEST_F(Helium_100_Live_Radio_Test, SetBeaconMessage)
{
int beacon_message_result = HE100_setBeaconMessage(fdin,3);
unsigned char payload[7] = {0x62,0x65,0x61,0x63,0x6F,0x6E,0x0A};
int beacon_message_result = HE100_setBeaconMessage(fdin,payload,7);

ASSERT_EQ(
0,
Expand All @@ -108,19 +111,19 @@ TEST_F(Helium_100_Live_Radio_Test, FastSetPA)
// Test softReset
TEST_F(Helium_100_Live_Radio_Test, SoftReset)
{
int soft_reset_result = HE100_softReset(fdin,7);
int soft_reset_result = HE100_softReset(fdin);

ASSERT_EQ(
0,
fast_set_pa_result
soft_reset_result
);
// TODO READ THE ACTUAL BYTE SEQUENCE RETURNED
}

// test readFirmwareRevision
TEST_F(Helium_100_Live_Radio_Test, ReadFirmwareRevision)
{
int read_firmware_result = HE100_readFirmwareRevision(fdin,7);
int read_firmware_result = HE100_readFirmwareRevision(fdin);

ASSERT_EQ(
0,
Expand All @@ -140,7 +143,7 @@ TEST_F(Helium_100_Live_Radio_Test, InvalidPALevel)
}

// BEACON TESTING
TEST_F(Helium_100_Live_Radio_Test, SetBeaconInterval)
TEST_F(Helium_100_Live_Radio_Test, SetBeaconThorough)
{
unsigned char set_beacon_expected_value[4][11] = {
{0x48,0x65,0x10,0x11,0x00,0x01,0x22,0x74,0x00,0xB8,0x28},
Expand Down

0 comments on commit 5099620

Please sign in to comment.