Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RadioObservatory
LOFAR
Commits
c39af27f
Commit
c39af27f
authored
12 years ago
by
Jan David Mol
Browse files
Options
Downloads
Patches
Plain Diff
Task #3696: Improved SharedMemory test
parent
bd66c434
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
RTCP/InputProc/test/tSharedMemory.cc
+97
-0
97 additions, 0 deletions
RTCP/InputProc/test/tSharedMemory.cc
with
97 additions
and
0 deletions
RTCP/InputProc/test/tSharedMemory.cc
+
97
−
0
View file @
c39af27f
#include
<lofar_config.h>
#include
"SharedMemory.h"
#include
<Common/LofarLogger.h>
#include
<Common/Thread/Thread.h>
#include
<unistd.h>
using
namespace
LOFAR
;
using
namespace
RTCP
;
Semaphore
semaphore
;
class
A
{
public:
void
creator
()
{
sleep
(
1
);
SharedMemoryArena
m
(
0x12345678
,
1024
,
SharedMemoryArena
::
CREATE
,
0
);
LOG_INFO
(
"Memory area created"
);
// wait for done
semaphore
.
down
();
}
void
reader
()
{
LOG_INFO
(
"Waiting for memory area"
);
SharedMemoryArena
m
(
0x12345678
,
1024
,
SharedMemoryArena
::
READ
,
2
);
LOG_INFO
(
"Memory area attached"
);
// signal done
semaphore
.
up
();
}
};
int
main
(
int
,
char
**
argv
)
{
INIT_LOGGER
(
argv
[
0
]
);
...
...
@@ -14,4 +43,72 @@ int main( int, char **argv ) {
SharedMemoryArena
m
(
0x12345678
,
1024
,
SharedMemoryArena
::
CREATE
,
0
);
}
/* Create a shared memory region and access it */
{
LOG_INFO
(
"Create shared memory region and access it"
);
SharedMemoryArena
x
(
0x12345678
,
1024
,
SharedMemoryArena
::
CREATE
,
0
);
SharedMemoryArena
y
(
0x12345678
,
1024
,
SharedMemoryArena
::
READ
,
0
);
}
/* Access a non-existing shared memory region */
{
LOG_INFO
(
"Access a non-existing shared memory region"
);
bool
caught_exception
=
false
;
try
{
SharedMemoryArena
y
(
0x12345678
,
1024
,
SharedMemoryArena
::
READ
,
0
);
}
catch
(
SystemCallException
&
e
)
{
caught_exception
=
true
;
}
ASSERT
(
caught_exception
);
}
/* Access a non-existing shared memory region, with timeout */
{
LOG_INFO
(
"Access a non-existing shared memory region"
);
bool
caught_exception
=
false
;
try
{
SharedMemoryArena
y
(
0x12345678
,
1024
,
SharedMemoryArena
::
READ
,
1
);
}
catch
(
SharedMemoryArena
::
TimeOutException
&
e
)
{
caught_exception
=
true
;
}
ASSERT
(
caught_exception
);
}
#ifdef USE_THREADS
LOG_INFO
(
"Debugging concurrent access"
);
{
/* Start reader before creator */
A
obj
;
// delayed creation of memory region
Thread
creator
(
&
obj
,
&
A
::
creator
);
// wait for access
obj
.
reader
();
}
#endif
/* Check whether memory access works as expected */
{
LOG_INFO
(
"Checking memory access through SharedStruct"
);
SharedStruct
<
int
>
writer
(
0x12345678
,
true
,
0
);
SharedStruct
<
int
>
reader
(
0x12345678
,
false
,
0
);
writer
.
get
()
=
42
;
ASSERT
(
reader
.
get
()
==
42
);
}
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment