Skip to content

Commit

Permalink
Unit-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
macmade committed Sep 16, 2020
1 parent e4450f1 commit 8bcdafb
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Expand Up @@ -52,3 +52,4 @@ FILES_C += $(call GET_C_FILES, $(DIR_SRC_FUNCTIONS)Log/)
# Gets every C file in the source directories (Unit-Tests)
FILES_C_TESTS += $(call GET_C_FILES, $(DIR_SRC_TESTS))
FILES_C_TESTS += $(call GET_C_FILES, $(DIR_SRC_TESTS)Atomic/)
FILES_C_TESTS += $(call GET_C_FILES, $(DIR_SRC_TESTS)SpinLock/)
40 changes: 40 additions & 0 deletions Unit-Tests/SpinLock/XSSpinLockLock.c
@@ -0,0 +1,40 @@
/*******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2020 Jean-David Gadina - www.xs-labs.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/

/*!
* @file XSSpinLockLock.c
* @copyright (c) 2020 - Jean-David Gadina - www.xs-labs.com
* @author Jean-David Gadina - www.xs-labs.com
*/

#include <XSCTest/XSCTest.h>
#include <XS/XS.h>

Test( SpinLock, XSSpinLockLock )
{
XSSpinLock lock = 0;

XSSpinLockLock( &lock );
AssertFalse( XSSpinLockTryLock( &lock ) );
}
42 changes: 42 additions & 0 deletions Unit-Tests/SpinLock/XSSpinLockTryLock.c
@@ -0,0 +1,42 @@
/*******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2020 Jean-David Gadina - www.xs-labs.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/

/*!
* @file XSSpinLockTryLock.c
* @copyright (c) 2020 - Jean-David Gadina - www.xs-labs.com
* @author Jean-David Gadina - www.xs-labs.com
*/

#include <XSCTest/XSCTest.h>
#include <XS/XS.h>

Test( SpinLock, XSSpinLockTryLock )
{
XSSpinLock lock = 0;

AssertTrue( XSSpinLockTryLock( &lock ) );
AssertFalse( XSSpinLockTryLock( &lock ) );
XSSpinLockUnlock( &lock );
AssertTrue( XSSpinLockTryLock( &lock ) );
}
42 changes: 42 additions & 0 deletions Unit-Tests/SpinLock/XSSpinLockUnlock.c
@@ -0,0 +1,42 @@
/*******************************************************************************
* The MIT License (MIT)
*
* Copyright (c) 2020 Jean-David Gadina - www.xs-labs.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/

/*!
* @file XSSpinLockUnlock.c
* @copyright (c) 2020 - Jean-David Gadina - www.xs-labs.com
* @author Jean-David Gadina - www.xs-labs.com
*/

#include <XSCTest/XSCTest.h>
#include <XS/XS.h>

Test( SpinLock, XSSpinLockUnlock )
{
XSSpinLock lock = 0;

XSSpinLockLock( &lock );
AssertFalse( XSSpinLockTryLock( &lock ) );
XSSpinLockUnlock( &lock );
AssertTrue( XSSpinLockTryLock( &lock ) );
}

0 comments on commit 8bcdafb

Please sign in to comment.