Increase inflation traverse extra node size; Handling of method code.
[SquirrelJME.git] / nanocoat / tests / testSpinLock.c
blobd9da5ea9bd24d2e9cc2ce6f05264a92d7349f62a
1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
10 #include <string.h>
12 #include "test.h"
13 #include "proto.h"
14 #include "mock.h"
15 #include "unit.h"
16 #include "sjme/multithread.h"
18 /**
19 * Tests spinlocks.
21 * @since 2024/07/31
23 SJME_TEST_DECLARE(testSpinLock)
25 sjme_errorCode error;
26 sjme_thread_spinLock lock;
27 sjme_jint count;
29 /* Zero out lock state. */
30 memset(&lock, 0, sizeof(lock));
32 /* Lock. */
33 error = sjme_thread_spinLockGrab(&lock);
34 sjme_unit_equalI(test, error, SJME_ERROR_NONE,
35 "Spin lock grab failed?");
36 sjme_unit_equalI(test, sjme_atomic_sjme_jint_get(&lock.count), 1,
37 "Spin lock count not one?");
39 /* Lock. */
40 error = sjme_thread_spinLockGrab(&lock);
41 sjme_unit_equalI(test, error, SJME_ERROR_NONE,
42 "Spin lock grab again failed?");
43 sjme_unit_equalI(test, sjme_atomic_sjme_jint_get(&lock.count), 2,
44 "Spin lock count not two?");
46 /* Unlock. */
47 count = -2;
48 error = sjme_thread_spinLockRelease(&lock, &count);
49 sjme_unit_equalI(test, error, SJME_ERROR_NONE,
50 "Spin lock release failed?");
51 sjme_unit_equalI(test, count, 1,
52 "Unlock count is not one?");
53 sjme_unit_equalI(test, sjme_atomic_sjme_jint_get(&lock.count), 1,
54 "Spin lock count not one?");
56 /* Unlock. */
57 count = -2;
58 error = sjme_thread_spinLockRelease(&lock, &count);
59 sjme_unit_equalI(test, error, SJME_ERROR_NONE,
60 "Spin lock release again failed?");
61 sjme_unit_equalI(test, count, 0,
62 "Unlock count is not zero?");
63 sjme_unit_equalI(test, sjme_atomic_sjme_jint_get(&lock.count), 0,
64 "Spin lock count not zero?");
66 /* Test done. */
67 return SJME_TEST_RESULT_PASS;