Skip to content

Commit

Permalink
Fixup unit tests on Linux
Browse files Browse the repository at this point in the history
Some unit tests were no longer passing on Linux platforms (e.g.
wp76).  Modify to re-enable or otherwise fix these tests on Linux.
This required a few changes on hl76 as well:

 - Mark tests which are not applicable to hl76 as skipped on that
   platform
 - Modify hl76 test runner to be more reliable with .08 firmware
   release.

Resolves: LE-13467
Change-Id: I809b6ebf4a2d7aff780a7a3a67aa40dccecfa600
  • Loading branch information
kdunwoody committed Oct 7, 2019
1 parent ab6d464 commit a5a73a3
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 70 deletions.
16 changes: 13 additions & 3 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def connect_target(app_name, target_name, baudrate=115200):
@return A pexpect wrapper around the connection that can be used to run tests.
"""
port = SerialPort.open(target_name)
port = SerialPort.open(target_name, baudrate)
if port:
app = port.io
gotConsole=False
Expand Down Expand Up @@ -602,10 +602,20 @@ def runtest(self):
adaptor = target_adaptor(self.config.getoption('target'))
if adaptor:
with adaptor.connect_target(SerialPort, self.name, dut, baudrate) as test_proc:
tap_output = test_loop(test_proc, catch_legato=False)
try:
tap_output = test_loop(test_proc, catch_legato=False)
adaptor.reset_target(SerialPort, test_proc)
except Exception, e:
adaptor.reset_target(SerialPort, test_proc)
raise e
else:
with connect_target(self.name, dut, baudrate) as test_proc:
tap_output = test_loop(test_proc, catch_legato=False)
try:
tap_output = test_loop(test_proc, catch_legato=False)
reset_target(test_proc)
except Exception, e:
reset_target(test_proc)
raise e

try:
self.add_report_section("call", "tap", tap_output)
Expand Down
2 changes: 0 additions & 2 deletions framework/test/crc/test_Crc.adef
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@ processes:
{
( testCrc )
}

maxStackBytes: 4K
}
91 changes: 51 additions & 40 deletions framework/test/fd/fdComponent/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@

// -------------------------------------------------------------------------------------------------
/**
* Test FIFO path.
* File path length
*/
// -------------------------------------------------------------------------------------------------
static const char FifoPath[] = "/tmp/fifoTestDevice";
#define PATH_LENGTH 128


// -------------------------------------------------------------------------------------------------
/**
* Buffers for test data.
*/
// -------------------------------------------------------------------------------------------------
static uint32_t ReadCrc;
static char ReadBufSmall[32];
static char ReadBufBig[100];
Expand Down Expand Up @@ -1015,8 +1011,6 @@ static void *FifoWriteMain(void *context)

LE_TEST_INFO("Write ended");

le_fd_Close(tCtx->fd);

return NULL;
}

Expand All @@ -1042,25 +1036,26 @@ COMPONENT_INIT
le_thread_Ref_t threadRRef, threadWRef;

// Create a fifo
LE_TEST_INFO("Create fifo '%s'", FifoPath);
res = le_fd_MkFifo(FifoPath, S_IRUSR | S_IWUSR);
static const char fifoPath[PATH_LENGTH] = "/tmp/fifoTestDevice";
LE_TEST_INFO("Create fifo '%s'", fifoPath);
res = le_fd_MkFifo(fifoPath, S_IRUSR | S_IWUSR);
LE_DEBUG("res = %d", res);
LE_TEST_OK((0 == res) || ((-1 == res) && (EEXIST == errno)), "fifo '%s' created", FifoPath);
LE_TEST_OK((0 == res) || ((-1 == res) && (EEXIST == errno)), "fifo '%s' created", fifoPath);

// small transfer
LE_INFO("Start small transfer test");

// Open the read end of the fifo
LE_TEST_INFO("Open read end of fifo '%s'", FifoPath);
fdR = le_fd_Open(FifoPath, O_RDONLY | O_NONBLOCK );
LE_TEST_INFO("Open read end of fifo '%s'", fifoPath);
fdR = le_fd_Open(fifoPath, O_RDONLY | O_NONBLOCK );
LE_DEBUG("fdR = %d", fdR);
LE_TEST_ASSERT(fdR != -1, "fifo read end '%s' opened", FifoPath);
LE_TEST_ASSERT(fdR != -1, "fifo read end '%s' opened", fifoPath);

// Open the write end of the fifo
LE_TEST_INFO("Open write end of fifo '%s'", FifoPath);
fdW = le_fd_Open(FifoPath, O_WRONLY );
LE_TEST_INFO("Open write end of fifo '%s'", fifoPath);
fdW = le_fd_Open(fifoPath, O_WRONLY );
LE_DEBUG("fdW = %d", fdW);
LE_TEST_ASSERT(fdW != -1, "fifo write end '%s' opened", FifoPath);
LE_TEST_ASSERT(fdW != -1, "fifo write end '%s' opened", fifoPath);

uint32_t dataCrc = le_crc_Crc32((uint8_t*)WriteBufSmall, sizeof(WriteBufSmall),
LE_CRC_START_CRC32);
Expand All @@ -1074,12 +1069,19 @@ COMPONENT_INIT
struct threadCtx tWCtx = { .fd = fdW, .buf = WriteBufSmall, .bufSize = sizeof(WriteBufSmall)};
threadWRef = le_thread_Create("Fifo Write Thread", FifoWriteMain, (void*)&tWCtx);

le_thread_SetPriority(threadRRef, LE_THREAD_PRIORITY_RT_17);
le_thread_SetPriority(threadWRef, LE_THREAD_PRIORITY_RT_17);
le_thread_SetJoinable(threadRRef);
le_thread_SetJoinable(threadWRef);

// start the threads
le_thread_Start(threadWRef);
le_thread_Start(threadRRef);
le_thread_Start(threadWRef);

le_thread_Join(threadWRef, NULL);
LE_TEST_INFO("Write thread join");
le_fd_Close(fdW);

le_thread_Join(threadRRef, NULL);
LE_TEST_INFO("Read thread join");
le_fd_Close(fdR);

LE_TEST_ASSERT(ReadSize == sizeof(WriteBufSmall), "Check read count: %" PRIuS, ReadSize);
Expand All @@ -1094,16 +1096,16 @@ COMPONENT_INIT
dataCrc = le_crc_Crc32((uint8_t*)WriteBufBig, sizeof(WriteBufBig), LE_CRC_START_CRC32);

// Open the read end of the fifo
LE_TEST_INFO("Open read end of fifo '%s'", FifoPath);
fdR = le_fd_Open(FifoPath, O_RDONLY | O_NONBLOCK);
LE_TEST_INFO("Open read end of fifo '%s'", fifoPath);
fdR = le_fd_Open(fifoPath, O_RDONLY | O_NONBLOCK);
LE_DEBUG("fdR = %d", fdR);
LE_TEST_ASSERT(fdR != -1, "fifo read end '%s' opened", FifoPath);
LE_TEST_ASSERT(fdR != -1, "fifo read end '%s' opened", fifoPath);

// Open the write end of the fifo
LE_TEST_INFO("Open write end of fifo '%s'", FifoPath);
fdW = le_fd_Open(FifoPath, O_WRONLY);
LE_TEST_INFO("Open write end of fifo '%s'", fifoPath);
fdW = le_fd_Open(fifoPath, O_WRONLY );
LE_DEBUG("fdW = %d", fdW);
LE_TEST_ASSERT(fdW != -1, "fifo write end '%s' opened", FifoPath);
LE_TEST_ASSERT(fdW != -1, "fifo write end '%s' opened", fifoPath);

ReadSize = 0;
WriteSize = 0;
Expand All @@ -1118,12 +1120,19 @@ COMPONENT_INIT
tWCtx.bufSize = sizeof(WriteBufBig);
threadWRef = le_thread_Create("Fifo Write Thread", FifoWriteMain, (void*)&tWCtx);

le_thread_SetPriority(threadRRef, LE_THREAD_PRIORITY_RT_17);
le_thread_SetPriority(threadWRef, LE_THREAD_PRIORITY_RT_17);
le_thread_SetJoinable(threadRRef);
le_thread_SetJoinable(threadWRef);

// start the threads
le_thread_Start(threadWRef);
le_thread_Start(threadRRef);
le_thread_Start(threadWRef);

le_thread_Join(threadWRef, NULL);
LE_TEST_INFO("Write thread join");
le_fd_Close(fdW);

le_thread_Join(threadRRef, NULL);
LE_TEST_INFO("Read thread join");
le_fd_Close(fdR);

LE_TEST_ASSERT(ReadSize == sizeof(WriteBufBig),
Expand All @@ -1140,40 +1149,42 @@ COMPONENT_INIT
LE_TEST_INFO("Start read end closure");

// Open the read end of the fifo
LE_TEST_INFO("Open read end of fifo '%s'", FifoPath);
fdR = le_fd_Open(FifoPath, O_RDONLY | O_NONBLOCK);
LE_TEST_INFO("Open read end of fifo '%s'", fifoPath);
fdR = le_fd_Open(fifoPath, O_RDONLY | O_NONBLOCK);
LE_DEBUG("fdR = %d", fdR);
LE_TEST_ASSERT(fdR != -1, "fifo read end '%s' opened", FifoPath);
LE_TEST_ASSERT(fdR != -1, "fifo read end '%s' opened", fifoPath);

// Open the write end of the fifo
LE_TEST_INFO("Open write end of fifo '%s'", FifoPath);
fdW = le_fd_Open(FifoPath, O_WRONLY );
LE_TEST_INFO("Open write end of fifo '%s'", fifoPath);
fdW = le_fd_Open(fifoPath, O_WRONLY );
LE_DEBUG("fdW = %d", fdW);
LE_TEST_ASSERT(fdW != -1, "fifo write end '%s' opened", FifoPath);
LE_TEST_ASSERT(fdW != -1, "fifo write end '%s' opened", fifoPath);

// create 2 thread: one for for read and the other for write operations
tRCtx.fd = fdR;
tRCtx.buf = ReadBufBig;
tRCtx.bufSize = sizeof(ReadBufBig);
threadRRef = le_thread_Create("Fifo Read Thread", FifoReadCloseMain, (void*)&tRCtx);
le_thread_SetPriority(threadRRef, LE_THREAD_PRIORITY_RT_17);
le_thread_SetJoinable(threadRRef);

// start the threads
le_thread_Start(threadRRef);

LE_TEST_INFO("Read thread complete");
le_thread_Join(threadRRef, NULL);
LE_TEST_INFO("Read thread join");


tWCtx.fd = fdW;
tWCtx.buf = WriteBufBig;
tWCtx.bufSize = sizeof(WriteBufBig);
threadWRef = le_thread_Create("Fifo Write Thread", FifoWriteReadCloseMain, (void*)&tWCtx);
le_thread_SetPriority(threadWRef, LE_THREAD_PRIORITY_RT_17);
le_thread_SetJoinable(threadWRef);

// start the threads
le_thread_Start(threadWRef);

LE_TEST_INFO("Write thread complete");
le_thread_Join(threadWRef, NULL);
LE_TEST_INFO("Write thread join");

LE_TEST_INFO("FD test end reached");
LE_TEST_EXIT;
Expand Down
4 changes: 4 additions & 0 deletions framework/test/issues/test_LE_2322.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
# The app is expected to abort when an attempt is made to access the thread info after cleanup.
#

import pytest

app_name = 'LE_2322'

@pytest.mark.skipif(pytest.config.getvalue('target') == 'hl76',
reason="Cannot read QXDM log from Python")
def testLogFilter(target):
assert target.expect('Legato threading API used in non-Legato thread!', timeout=10) == 0, \
'Missing non-Legato thread error'
4 changes: 4 additions & 0 deletions framework/test/log/test_Log.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Test harness for log testing
#

import pytest, os

app_name = 'logTester'
logStrings = [ '[^|]* \| [^|]* \| frame 0 msg',
'[^|]* \| [^|]* \| frame 1 msg',
Expand All @@ -10,6 +12,8 @@
'[^|]* \| [^|]* \| frame 4 msg',
'[^|]* \| [^|]* \| frame 5 msg' ]

@pytest.mark.skipif(pytest.config.getvalue('target') == 'hl76',
reason="Cannot read QXDM log from Python")
def testLogFilter(target):
for filterLevel in range(len(logStrings)):
for message in range(filterLevel,len(logStrings)):
Expand Down
22 changes: 3 additions & 19 deletions framework/test/testFramework.sdef
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ apps:
semaphore/test_Semaphore
random/test_Random
#if ${LE_CONFIG_NETWORK} = y
#if ${LEGATO_TARGET} = hl76
#else
fdMonitor/test_FdMonitorSocket
#endif
#endif
fdMonitor/test_FdMonitorFifo
ipc/test_IpcC2C
Expand Down Expand Up @@ -58,25 +61,6 @@ apps:
multi-app/helloWorld
log/logTester
issues/LE_2322
// Framework Tools.
#if ${DISABLE_FRAMEWORK_TOOLS} = 1
#else
#if ${LE_CONFIG_LINUX} = y
#else
// $LEGATO_ROOT/framework/tools/target/rtos/targetTools.adef
#endif
#endif
}

commands:
{
#if ${LE_CONFIG_LINUX} = y
#else
// legato = targetTools:/legato
#endif
#if ${LE_CONFIG_RTOS_TARGET_TOOL_INSPECT} = y
// inspect = targetTools:/inspect
#endif
}

cflags:
Expand Down
7 changes: 2 additions & 5 deletions framework/test/timer/timerComponent/testTimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,11 @@ static void TimerExpiryHandler
{
LE_TEST_OK(TimerTestDataArray[i].testPassed[1][j],
"Main timer %" PRIuS " expiry %" PRIu32 " accuracy within tolerance", i, j);
#if LE_CONFIG_LINUX
LE_TEST_BEGIN_SKIP(!LE_CONFIG_IS_ENABLED(LE_CONFIG_LINUX), 1);
LE_TEST_OK(TimerTestDataArray[i].testPassed[0][j],
"Child timer %" PRIuS " expiry %" PRIu32 " accuracy within tolerance",
i, j);
#endif /* end LE_CONFIG_LINUX */
LE_TEST_END_SKIP();
}
}

Expand Down Expand Up @@ -521,13 +521,10 @@ COMPONENT_INIT

LE_ASSERT(pthread_key_create(&StartTimeKey, NULL) == 0);

// Skip child timer tests on RTOS as timer accuracy isn't good enough
LE_TEST_BEGIN_SKIP(!LE_CONFIG_IS_ENABLED(LE_CONFIG_LINUX), Total);
#if LE_CONFIG_LINUX
le_thread_SetJoinable(ChildThread);
le_thread_Start(ChildThread);
#endif
LE_TEST_END_SKIP();

TimerEventLoopTest();
LE_TEST_INFO("==== Timer Tests Started ====\n");
Expand Down
3 changes: 2 additions & 1 deletion run-tests
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,8 @@ function ExecTargetPyTest()
fi

py.test --junitxml="build/$TARGET_TYPE/tests/results/$(echo ${pytest_name} | tr '/' '_').xml" \
--target=$DEST_IP \
--dut=$DEST_IP \
--target=$TARGET_TYPE \
"${pytest_name}"
if [ $? -ne 0 ]; then
message $COLOR_ERROR "'${pytest_name}' tests failed"
Expand Down

0 comments on commit a5a73a3

Please sign in to comment.