Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 23656fa

Browse files
adrpoOpenModelica-Hudson
authored andcommitted
allow disabling of 'stdout' and 'assert' streams
Belonging to [master]: - #2573
1 parent 578550f commit 23656fa

File tree

3 files changed

+45
-35
lines changed

3 files changed

+45
-35
lines changed

SimulationRuntime/c/simulation/simulation_runtime.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ void setGlobalVerboseLevel(int argc, char**argv)
131131
return; // no lv flag given.
132132
}
133133

134+
/* default activated, but it can be disabled with -stdout or -assert */
135+
useStream[LOG_STDOUT] = 1;
136+
useStream[LOG_ASSERT] = 1;
137+
134138
if(flags->find("LOG_ALL", 0) != string::npos)
135139
{
136140
for(i=1; i<SIM_LOG_MAX; ++i)
@@ -181,10 +185,6 @@ void setGlobalVerboseLevel(int argc, char**argv)
181185
}while(pos != string::npos);
182186
}
183187

184-
/* default activated */
185-
useStream[LOG_STDOUT] = 1;
186-
useStream[LOG_ASSERT] = 1;
187-
188188
/* print LOG_SOTI if LOG_INIT is enabled */
189189
if(useStream[LOG_INIT])
190190
useStream[LOG_SOTI] = 1;

SimulationRuntime/c/util/omc_error.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
/* For MMC_THROW, so we can end this thing */
3535
#include "meta/meta_modelica.h"
3636

37-
const int firstOMCErrorStream = 3;
37+
const int firstOMCErrorStream = 1;
3838

3939
const char *LOG_STREAM_NAME[SIM_LOG_MAX] = {
4040
"LOG_UNKNOWN",
@@ -85,8 +85,8 @@ const char *LOG_STREAM_NAME[SIM_LOG_MAX] = {
8585

8686
const char *LOG_STREAM_DESC[SIM_LOG_MAX] = {
8787
"unknown",
88-
"this stream is always active", /* LOG_STDOUT */
89-
"this stream is always active", /* LOG_ASSERT */
88+
"this stream is always active, can be disabled with -lv=-stdout", /* LOG_STDOUT */
89+
"this stream is always active, can be disabled with -lv=-assert", /* LOG_ASSERT */
9090

9191
"additional information about dassl solver", /* LOG_DASSL */
9292
"outputs the states at every dassl call", /* LOG_DASSL_STATES */

SimulationRuntime/cpp/omcCAPI/src/OMCTest.cpp

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,37 @@
22
#include "OMC.h"
33
#include <string>
44
#include <iostream>
5-
#include "meta/meta_modelica.h"
5+
#include <thread>
6+
7+
#define GC_THREADS
8+
#include "gc.h"
9+
610
/*
711
#include <boost/thread.hpp>
812
#include <boost/chrono.hpp>
913
*/
10-
#include <pthread.h>
11-
void runTest(OMCData* omcData, std::string testfolder, std::string omhome)
14+
15+
void runTest(std::string testfolder, std::string omhome)
1216
{
17+
18+
GC_stack_base sb;
19+
GC_get_stack_base(&sb);
20+
GC_register_my_thread(&sb);
21+
1322
int status = 0;
1423
char *change_dir_results = 0, *mkDirResults = 0, *version = 0, *errorMsg2 = 0, *simulateResult = 0, *clear = 0;
1524

25+
OMCData *omcData;
26+
std::cout << "Initialize OMC, use gcc compiler on folder: " << testfolder << std::endl;
27+
// if you send in 1 here it will crash on Windows, i need do debug more why this happens
28+
status = InitOMC(&omcData, "gcc", "");
29+
if(status > 0)
30+
std::cout << "..ok" << std::endl;
31+
else
32+
std::cout << "..failed" << std::endl;
33+
/*----------------------------------------*/
34+
35+
1636
// create the test folder
1737
std::cout << "Create working directory of OMC: " << testfolder << std::endl;
1838
std::string mkDir = "mkdir(\"" + testfolder + "\")";
@@ -97,39 +117,29 @@ void runTest(OMCData* omcData, std::string testfolder, std::string omhome)
97117
std::cout << "..ok " << clear << std::endl;
98118
else
99119
std::cout << "..failed" << std::endl;
120+
121+
GC_unregister_my_thread();
100122
}
101123

124+
#define MAX_THREADS 4
125+
102126
int main(int argc, const char* argv[])
103127
{
104-
OMCData *omcData = 0;
105-
int status = 0;
128+
std::thread threads[MAX_THREADS];
129+
int i = 0;
106130

107131
std::cout << "Test OMC C-API dll ..." << std::endl;
108132
InitMetaOMC();
133+
GC_allow_register_threads();
109134

110-
/*----------------------------------------*/
111-
std::cout << "Initialize OMC, use gcc compiler" << std::endl;
112-
// if you send in 1 here it will crash on Windows, i need do debug more why this happens
113-
status = InitOMC(&omcData, "gcc", "");
114-
if(status > 0)
115-
std::cout << "..ok" << std::endl;
116-
else
117-
std::cout << "..failed" << std::endl;
118-
/*----------------------------------------*/
119-
120-
121-
std::cout << "starting test 1" << std::endl;
122-
std::string dir = "./tmp1";
123-
runTest(omcData, dir, "");
124-
std::cout << "starting test 2" << std::endl;
125-
dir = "./tmp2";
126-
runTest(omcData, dir, "");
127-
std::cout << "starting test 3" << std::endl;
128-
dir = "./tmp3";
129-
runTest(omcData, dir, "");
130-
131-
/*------------------------------------------*/
135+
for (i = 0; i < MAX_THREADS; i++)
136+
{
137+
std::string dir = std::string("./tmp") + std::to_string(i);
138+
threads[i] = std::thread(runTest, dir, "");
139+
}
132140

133-
FreeOMC(omcData);
141+
for (i = 0; i < MAX_THREADS; i++)
142+
if (threads[i].joinable())
143+
threads[i].join();
134144
}
135145

0 commit comments

Comments
 (0)