mirror of https://github.com/pvnis/srsRAN_4G.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
2.5 KiB
C++
116 lines
2.5 KiB
C++
6 years ago
|
/*
|
||
5 years ago
|
* Copyright 2013-2020 Software Radio Systems Limited
|
||
8 years ago
|
*
|
||
6 years ago
|
* This file is part of srsLTE.
|
||
8 years ago
|
*
|
||
6 years ago
|
* srsLTE is free software: you can redistribute it and/or modify
|
||
8 years ago
|
* it under the terms of the GNU Affero General Public License as
|
||
|
* published by the Free Software Foundation, either version 3 of
|
||
|
* the License, or (at your option) any later version.
|
||
|
*
|
||
6 years ago
|
* srsLTE is distributed in the hope that it will be useful,
|
||
8 years ago
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU Affero General Public License for more details.
|
||
|
*
|
||
|
* A copy of the GNU Affero General Public License can be found in
|
||
|
* the LICENSE file in the top-level directory of this distribution
|
||
|
* and at http://www.gnu.org/licenses/.
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
#define NTHREADS 100
|
||
5 years ago
|
#define NMSGS 100
|
||
8 years ago
|
|
||
8 years ago
|
#include "srslte/common/logger_file.h"
|
||
5 years ago
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
8 years ago
|
|
||
|
using namespace srslte;
|
||
|
|
||
|
typedef struct {
|
||
5 years ago
|
logger_file* l;
|
||
|
int thread_id;
|
||
|
} args_t;
|
||
8 years ago
|
|
||
5 years ago
|
void* thread_loop(void* a)
|
||
|
{
|
||
|
args_t* args = (args_t*)a;
|
||
|
char buf[100];
|
||
|
for (int i = 0; i < NMSGS; i++) {
|
||
8 years ago
|
sprintf(buf, "Thread %d: %d", args->thread_id, i);
|
||
5 years ago
|
args->l->log_char(buf);
|
||
8 years ago
|
}
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
5 years ago
|
void write(std::string filename)
|
||
|
{
|
||
8 years ago
|
logger_file l;
|
||
8 years ago
|
l.init(filename);
|
||
|
pthread_t threads[NTHREADS];
|
||
|
args_t args[NTHREADS];
|
||
5 years ago
|
for (int i = 0; i < NTHREADS; i++) {
|
||
|
args[i].l = &l;
|
||
8 years ago
|
args[i].thread_id = i;
|
||
|
pthread_create(&threads[i], NULL, &thread_loop, &args[i]);
|
||
|
}
|
||
5 years ago
|
for (int i = 0; i < NTHREADS; i++) {
|
||
8 years ago
|
pthread_join(threads[i], NULL);
|
||
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
bool read(std::string filename)
|
||
|
{
|
||
8 years ago
|
bool pass = true;
|
||
|
bool written[NTHREADS][NMSGS];
|
||
5 years ago
|
int thread = 0, msg = 0;
|
||
|
int r;
|
||
8 years ago
|
|
||
5 years ago
|
for (int i = 0; i < NTHREADS; i++) {
|
||
|
for (int j = 0; j < NMSGS; j++) {
|
||
8 years ago
|
written[i][j] = false;
|
||
|
}
|
||
|
}
|
||
5 years ago
|
FILE* f = fopen(filename.c_str(), "r");
|
||
|
if (f != NULL) {
|
||
|
while (fscanf(f, "Thread %d: %d\n", &thread, &msg)) {
|
||
7 years ago
|
if (thread < NTHREADS && msg < NMSGS) {
|
||
|
written[thread][msg] = true;
|
||
|
} else {
|
||
|
perror("Wrong thread and/or msg");
|
||
7 years ago
|
fclose(f);
|
||
7 years ago
|
return false;
|
||
|
}
|
||
8 years ago
|
}
|
||
|
fclose(f);
|
||
|
}
|
||
5 years ago
|
for (int i = 0; i < NTHREADS; i++) {
|
||
|
for (int j = 0; j < NMSGS; j++) {
|
||
|
if (!written[i][j])
|
||
|
pass = false;
|
||
8 years ago
|
}
|
||
|
}
|
||
|
return pass;
|
||
|
}
|
||
|
|
||
5 years ago
|
int main(int argc, char** argv)
|
||
|
{
|
||
|
bool result;
|
||
8 years ago
|
std::string f("log.txt");
|
||
|
write(f);
|
||
|
result = read(f);
|
||
7 years ago
|
|
||
|
if (remove(f.c_str())) {
|
||
|
perror("Removing file");
|
||
|
}
|
||
|
|
||
5 years ago
|
if (result) {
|
||
8 years ago
|
printf("Passed\n");
|
||
|
exit(0);
|
||
5 years ago
|
} else {
|
||
8 years ago
|
printf("Failed\n;");
|
||
|
exit(1);
|
||
|
}
|
||
|
}
|