mirror of
git://nv-tegra.nvidia.com/linux-nvgpu.git
synced 2025-12-22 09:12:24 +03:00
gpu: nvgpu: unit: Update interface.lock unit tests
Implement APIs which mimic below QNX standard APIs and use them in interface.lock unit tests. This is required because as part of writing UTs for "daemon_igpu.c" file, the below standard APIs are mocked. - sem_init() - sem_wait() - sem_post() JIRA NVGPU-3909 Change-Id: I8f7e9c031b2a840e04e03a0f871a9e5d72c3e4dd Signed-off-by: Petlozu Pravareshwar <petlozup@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2293634 Tested-by: mobile promotions <svcmobile_promotions@nvidia.com> Reviewed-by: Philip Elcan <pelcan@nvidia.com> Reviewed-by: Vijayakumar Subbu <vsubbu@nvidia.com> Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com> GVS: Gerrit_Virtual_Submit
This commit is contained in:
committed by
Alex Waterman
parent
c6a0ffe0d6
commit
566b1df08c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
|
||||
* Copyright (c) 2019-2020, NVIDIA CORPORATION. All rights reserved.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
@@ -30,7 +30,7 @@
|
||||
#include <nvgpu/lock.h>
|
||||
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "lock.h"
|
||||
|
||||
@@ -42,9 +42,44 @@ struct worker_parameters {
|
||||
struct nvgpu_raw_spinlock *raw_lock;
|
||||
};
|
||||
|
||||
sem_t worker_sem;
|
||||
int worker_sem = -1;
|
||||
/* Mutex for atomicity of operations on "worker_sem" */
|
||||
pthread_mutex_t nvgpu_sem_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
bool test_shared_flag;
|
||||
|
||||
static void nvgpu_sem_init(int *sem)
|
||||
{
|
||||
(*sem) = -1;
|
||||
pthread_mutex_init(&nvgpu_sem_mutex, NULL);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void nvgpu_sem_post(int *sem)
|
||||
{
|
||||
pthread_mutex_lock(&nvgpu_sem_mutex);
|
||||
(*sem) = (*sem) + 1;
|
||||
pthread_mutex_unlock(&nvgpu_sem_mutex);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void nvgpu_sem_wait(int *sem)
|
||||
{
|
||||
pthread_mutex_lock(&nvgpu_sem_mutex);
|
||||
while ((*sem) == -1) {
|
||||
pthread_mutex_unlock(&nvgpu_sem_mutex);
|
||||
/* Wait for 1 msec */
|
||||
usleep(1000);
|
||||
pthread_mutex_lock(&nvgpu_sem_mutex);
|
||||
}
|
||||
|
||||
(*sem) = (*sem) - 1;
|
||||
pthread_mutex_unlock(&nvgpu_sem_mutex);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int test_mutex_init(struct unit_module *m, struct gk20a *g, void *args)
|
||||
{
|
||||
struct nvgpu_mutex mutex;
|
||||
@@ -95,7 +130,7 @@ static void *lock_worker(void *args)
|
||||
struct worker_parameters *params = (struct worker_parameters *) args;
|
||||
|
||||
/* Signal main testing function that the worker thread has started. */
|
||||
sem_post(&worker_sem);
|
||||
nvgpu_sem_post(&worker_sem);
|
||||
|
||||
/*
|
||||
* Lock should already be held by the main test function, so execution
|
||||
@@ -120,7 +155,7 @@ static void *lock_worker(void *args)
|
||||
* succeeded and signal the main thread.
|
||||
*/
|
||||
test_shared_flag = true;
|
||||
sem_post(&worker_sem);
|
||||
nvgpu_sem_post(&worker_sem);
|
||||
|
||||
/* Cleanup */
|
||||
switch (params->type) {
|
||||
@@ -180,7 +215,7 @@ int test_lock_acquire_release(struct unit_module *m, struct gk20a *g,
|
||||
* current thread and the worker thread
|
||||
* (*_acquire_release_worker)
|
||||
*/
|
||||
sem_init(&worker_sem, 0, 0);
|
||||
nvgpu_sem_init(&worker_sem);
|
||||
test_shared_flag = false;
|
||||
|
||||
/*
|
||||
@@ -205,7 +240,7 @@ int test_lock_acquire_release(struct unit_module *m, struct gk20a *g,
|
||||
pthread_create(&worker_thread, NULL, lock_worker,
|
||||
(void *) &worker_params);
|
||||
|
||||
sem_wait(&worker_sem);
|
||||
nvgpu_sem_wait(&worker_sem);
|
||||
|
||||
/*
|
||||
* Worker thread is initialized and running. It should be waiting on the
|
||||
@@ -234,7 +269,7 @@ int test_lock_acquire_release(struct unit_module *m, struct gk20a *g,
|
||||
break;
|
||||
}
|
||||
|
||||
sem_wait(&worker_sem);
|
||||
nvgpu_sem_wait(&worker_sem);
|
||||
|
||||
if (!test_shared_flag) {
|
||||
unit_err(m, "Lock did not get released in worker thread\n");
|
||||
@@ -248,7 +283,6 @@ cleanup:
|
||||
if (type == TYPE_MUTEX) {
|
||||
nvgpu_mutex_destroy(&mutex);
|
||||
}
|
||||
sem_destroy(&worker_sem);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user