cmsis_mutex_func_test.c 8.8 KB
Newer Older
W
wenjun 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
/**
 * Copyright (c) 2020 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
#include "hos_types.h"
#include <securec.h>
#include "hctest.h"
#include "los_config.h"
#include "cmsis_os2.h"
#include "kernel_test.h"

#define LOS_WAIT_FOREVER 0xFFFFFFFF

UINT16 g_cmsisTestMutexCount;
osMutexId_t g_cmsisMutexId;
osMutexAttr_t g_cmsisMutexAttr;

/**
 * @tc.desc      : register a test suite, this suite is used to test basic flow and interface dependency
 * @param        : subsystem name is utils
 * @param        : module name is utilsFile
 * @param        : test suit name is CmsisMutexFuncTestSuite
 */
LITE_TEST_SUIT(Cmsis, Cmsismutex, CmsisMutexFuncTestSuite);

/**
 * @tc.setup     : setup for all testcases
 * @return       : setup result, TRUE is success, FALSE is fail
 */
static BOOL CmsisMutexFuncTestSuiteSetUp(void)
{
    return TRUE;
}

/**
 * @tc.teardown  : teardown for all testcases
 * @return       : teardown result, TRUE is success, FALSE is fail
 */
static BOOL CmsisMutexFuncTestSuiteTearDown(void)
{
    printf("+-------------------------------------------+\n");
    return TRUE;
}

static void CmsisMutexGetOwnerFunc001(void const *argument)
{
    (void)argument;
    osStatus_t uwRet;
    osThreadId_t id1;
    osThreadId_t id2;
    osThreadAttr_t attr;
    g_cmsisMutexId = osMutexNew(&g_cmsisMutexAttr);
    TEST_ASSERT_NOT_NULL(g_cmsisMutexId);

    uwRet = osMutexAcquire(g_cmsisMutexId, LOS_WAIT_FOREVER);
    TEST_ASSERT_EQUAL_INT(osOK, uwRet);

    id1 = osMutexGetOwner(g_cmsisMutexId);
    id2 = osThreadGetId(); 
    TEST_ASSERT_EQUAL_STRING(id1, id2);

    attr.name = osThreadGetName(id1);
    TEST_ASSERT_EQUAL_STRING("testMutexGetOwner001", attr.name);
    
    uwRet = osMutexRelease(g_cmsisMutexId);
    TEST_ASSERT_EQUAL_INT(osOK, uwRet);

    uwRet = osMutexDelete(g_cmsisMutexId);
    TEST_ASSERT_EQUAL_INT(osOK, uwRet);
    osThreadExit();
}

/**
 * @tc.number    : SUB_KERNEL_CMSIS_MUTEX_OPERATION_100
 * @tc.name      : mutex operation for creat
 * @tc.desc      : [C- SOFTWARE -0200]
 * @tc.size      : MEDIUM
 * @tc.type      : FUNC
 * @tc.level     : Level 1
 */
LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexNew001, LEVEL1)
{
    g_cmsisMutexId = osMutexNew(NULL);
    TEST_ASSERT_NOT_NULL(g_cmsisMutexId);
    (void)osMutexDelete(g_cmsisMutexId);
    osDelay(DELAY_TICKS_5);
};

/**
 * @tc.number    : SUB_KERNEL_CMSIS_MUTEX_OPERATION_100
 * @tc.name      : mutex operation for creat
 * @tc.desc      : [C- SOFTWARE -0200]
 * @tc.size      : MEDIUM
 * @tc.type      : FUNC
 * @tc.level     : Level 1
 */
LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexNew002, LEVEL1)
{
    g_cmsisMutexId = osMutexNew(&g_cmsisMutexAttr);
    TEST_ASSERT_NOT_NULL(g_cmsisMutexId);
    (void)osMutexDelete(g_cmsisMutexId);
    osDelay(DELAY_TICKS_5);
};

/**
 * @tc.number    : SUB_KERNEL_CMSIS_MUTEX_OPERATION_100
 * @tc.name      : mutex operation for delete
 * @tc.desc      : [C- SOFTWARE -0200]
 * @tc.size      : MEDIUM
 * @tc.type      : FUNC
 * @tc.level     : Level 1
 */
LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexDelete001, LEVEL1)
{
    osStatus_t uwRet;
    g_cmsisMutexId = osMutexNew(NULL);
    TEST_ASSERT_NOT_NULL(g_cmsisMutexId);
    uwRet = osMutexDelete(g_cmsisMutexId);
    TEST_ASSERT_EQUAL_INT(osOK, uwRet);

    uwRet = osMutexDelete(g_cmsisMutexId);
    TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet);
};

/**
 * @tc.number    : SUB_KERNEL_CMSIS_MUTEX_OPERATION_100
 * @tc.name      : mutex operation for delete
 * @tc.desc      : [C- SOFTWARE -0200]
 * @tc.size      : MEDIUM
 * @tc.type      : FUNC
 * @tc.level     : Level 1
 */
LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexDelete002, LEVEL1)
{
    osStatus_t uwRet;
    g_cmsisMutexId = osMutexNew(&g_cmsisMutexAttr);
    TEST_ASSERT_NOT_NULL(g_cmsisMutexId);
    uwRet = osMutexDelete(g_cmsisMutexId);
    TEST_ASSERT_EQUAL_INT(osOK, uwRet);

    uwRet = osMutexDelete(g_cmsisMutexId);
    TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet);
};

/**
 * @tc.number    : SUB_KERNEL_CMSIS_MUTEX_OPERATION_100
 * @tc.name      : mutex operation for acquire
 * @tc.desc      : [C- SOFTWARE -0200]
 * @tc.size      : MEDIUM
 * @tc.type      : FUNC
 * @tc.level     : Level 1
 */
LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexDelete003, LEVEL1)
{
    osStatus_t uwRet;
    g_cmsisMutexId = osMutexNew(NULL);
    TEST_ASSERT_NOT_NULL(g_cmsisMutexId);

    osMutexAcquire(g_cmsisMutexId, LOS_WAIT_FOREVER);
    uwRet = osMutexDelete(g_cmsisMutexId);
    TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet);

    osMutexRelease(g_cmsisMutexId);
    uwRet = osMutexDelete(g_cmsisMutexId);
    TEST_ASSERT_EQUAL_INT(osOK, uwRet);
};

/**
 * @tc.number    : SUB_KERNEL_CMSIS_MUTEX_OPERATION_100
 * @tc.name      : mutex delete operation with mutex_id = NULL
 * @tc.desc      : [C- SOFTWARE -0200]
 * @tc.size      : MEDIUM
 * @tc.type      : FUNC
 * @tc.level     : Level 1
 */
LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexDelete004, LEVEL1)
{
    osStatus_t uwRet;
    uwRet = osMutexDelete(NULL);
    TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet);
};

/**
 * @tc.number    : SUB_KERNEL_CMSIS_MUTEX_OPERATION_100
 * @tc.name      : mutex acquire operation with mutex_id = NULL
 * @tc.desc      : [C- SOFTWARE -0200]
 * @tc.size      : MEDIUM
 * @tc.type      : FUNC
 * @tc.level     : Level 1
 */
LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexAcquire001, LEVEL1)
{
    osStatus_t uwRet;
    uwRet = osMutexAcquire(NULL, LOS_WAIT_FOREVER);
    TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet);
};

/**
 * @tc.number    : SUB_KERNEL_CMSIS_MUTEX_OPERATION_100
 * @tc.name      : mutex operation for acquire
 * @tc.desc      : [C- SOFTWARE -0200]
 * @tc.size      : MEDIUM
 * @tc.type      : FUNC
 * @tc.level     : Level 1
 */
LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexAcquire002, LEVEL1)
{
    osStatus_t uwRet;
    g_cmsisMutexId = osMutexNew(&g_cmsisMutexAttr);
    TEST_ASSERT_NOT_NULL(g_cmsisMutexId);

    uwRet = osMutexAcquire(g_cmsisMutexId, LOS_WAIT_FOREVER);
    TEST_ASSERT_EQUAL_INT(osOK, uwRet);

    (void)osMutexRelease(g_cmsisMutexId);
    uwRet = osMutexDelete(g_cmsisMutexId);
    TEST_ASSERT_EQUAL_INT(osOK, uwRet);
};

/**
 * @tc.number    : SUB_KERNEL_CMSIS_MUTEX_OPERATION_100
 * @tc.name      : mutex operation for release
 * @tc.desc      : [C- SOFTWARE -0200]
 * @tc.size      : MEDIUM
 * @tc.type      : FUNC
 * @tc.level     : Level 1
 */
LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexRelease001, LEVEL1)
{
    osStatus_t uwRet;
    g_cmsisMutexId = osMutexNew(&g_cmsisMutexAttr);
    TEST_ASSERT_NOT_NULL(g_cmsisMutexId);

    uwRet = osMutexAcquire(g_cmsisMutexId, LOS_WAIT_FOREVER);
    TEST_ASSERT_EQUAL_INT(osOK, uwRet);

    uwRet = osMutexDelete(g_cmsisMutexId);
    TEST_ASSERT_EQUAL_INT(osErrorResource, uwRet);

    uwRet = osMutexRelease(g_cmsisMutexId);
    TEST_ASSERT_EQUAL_INT(osOK, uwRet);

    uwRet = osMutexDelete(g_cmsisMutexId);
    TEST_ASSERT_EQUAL_INT(osOK, uwRet);
};

/**
 * @tc.number    : SUB_KERNEL_CMSIS_MUTEX_OPERATION_100
 * @tc.name      : mutex release operation with mutex_id = NULL
 * @tc.desc      : [C- SOFTWARE -0200]
 * @tc.size      : MEDIUM
 * @tc.type      : FUNC
 * @tc.level     : Level 1
 */
LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexRelease002, LEVEL1)
{
    osStatus_t uwRet;
    uwRet = osMutexRelease(NULL);
    TEST_ASSERT_EQUAL_INT(osErrorParameter, uwRet);
};

/**
 * @tc.number    : SUB_KERNEL_CMSIS_MUTEX_OPERATION_100
 * @tc.name      : mutex operation for get owner
 * @tc.desc      : [C- SOFTWARE -0200]
 * @tc.size      : MEDIUM
 * @tc.type      : FUNC
 * @tc.level     : Level 1
 */
LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexGetOwner001, LEVEL1)
{
    osThreadId_t id;
    osThreadAttr_t attr;
    attr.name = "testMutexGetOwner001";
    attr.attr_bits = 0U;
    attr.cb_mem = NULL;
    attr.cb_size = 0U;
    attr.stack_mem = NULL;
    attr.stack_size = TEST_TASK_STACK_SIZE;
    attr.priority = osPriorityAboveNormal;
    id = osThreadNew((osThreadFunc_t)CmsisMutexGetOwnerFunc001, NULL, &attr);
    TEST_ASSERT_NOT_NULL(id);
};

/**
 * @tc.number    : SUB_KERNEL_CMSIS_MUTEX_OPERATION_100
 * @tc.name      : mutex get owner operation with mutex_id = NULL
 * @tc.desc      : [C- SOFTWARE -0200]
 * @tc.size      : MEDIUM
 * @tc.type      : FUNC
 * @tc.level     : Level 1
 */
LITE_TEST_CASE(CmsisMutexFuncTestSuite, testOsMutexGetOwner002, LEVEL1)
{
    osThreadId_t id;
    id = osMutexGetOwner(NULL);
    TEST_ASSERT_NULL(id);
};

RUN_TEST_SUITE(CmsisMutexFuncTestSuite);