You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.1 KiB

#include <cxxtest/TestSuite.h>
#include "Common.hpp"
#include "Fixture.hpp"
#include "Mutex.hpp"
#include <errno.h> // EDEADLK, EPERM, ETIMEDOUT
class TestMutex : public CxxTest::TestSuite
{
public:
void testBasic( void )
{
TEST_HEADER;
Mutex m;
TS_ASSERT_EQUALS ( m.lock() , 0 );
// TS_ASSERT_EQUALS ( m.lock() , 0 ); that would be a deadlock
TS_ASSERT_EQUALS ( m.tryLock(0), EBUSY );
TS_ASSERT_EQUALS ( m.tryLock(2), ETIMEDOUT );
TS_ASSERT_EQUALS ( m.unlock() , 0 );
TS_ASSERT_EQUALS ( m.unlock() , 0 );
}
void testErrorCheck( void )
{
TEST_HEADER;
Mutex m(Mutex::ErrorCheck);
TS_ASSERT_EQUALS ( m.lock() , 0 );
TS_ASSERT_EQUALS ( m.lock(), EDEADLK );
TS_ASSERT_EQUALS ( m.unlock() , 0 );
TS_ASSERT_EQUALS ( m.unlock() , EPERM );
}
void testRecursive( void )
{
TEST_HEADER;
Mutex m(Mutex::Recursive);
TS_ASSERT_EQUALS ( m.lock() , 0 );
TS_ASSERT_EQUALS ( m.lock() , 0 );
TS_ASSERT_EQUALS ( m.unlock() , 0 );
TS_ASSERT_EQUALS ( m.unlock() , 0 );
TS_ASSERT_EQUALS ( m.unlock() , EPERM );
}
};