Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
scdaq
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue 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
scouting-demonstrator
scdaq
Commits
161267f0
Commit
161267f0
authored
7 months ago
by
Giovanna Lazzari Miotto
Browse files
Options
Downloads
Patches
Plain Diff
improve creat
parent
da09e1d8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#8028389
failed
7 months ago
Stage: check
Stage: build
Stage: run
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/testing_scripts/creat_test.cpp
+43
-14
43 additions, 14 deletions
test/testing_scripts/creat_test.cpp
with
43 additions
and
14 deletions
test/testing_scripts/creat_test.cpp
+
43
−
14
View file @
161267f0
#include
<errno.h>
#include
<fcntl.h>
#include
<linux/famfs_ioctl.h>
//
#include <linux/famfs_ioctl.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<sys/mman.h>
#include
<unistd.h>
#include
<iostream>
...
...
@@ -17,9 +18,7 @@ void generate_random_data(char *buffer, size_t length) {
buffer
[
length
]
=
'\0'
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
<
4
)
{
std
::
cout
<<
"Wrong number of arguments"
<<
std
::
endl
;
return
-
1
;
...
...
@@ -39,32 +38,62 @@ int main(int argc, char* argv[]) {
}
generate_random_data
(
data
,
length
-
1
);
std
::
cout
<<
"=== Data generated ==="
<<
std
::
endl
;
// open()
std
::
string
open_filepath
=
filepath
+
"_
open
"
;
std
::
string
open_filepath
=
filepath
+
"_
write
"
;
std
::
cout
<<
"Attempting to call open() on FAMFS for filename="
<<
open_filepath
<<
std
::
endl
;
int
fd
=
open
(
open_filepath
.
c_str
(),
O_CREAT
|
O_RDWR
);
if
(
fd
<
0
)
{
std
::
cout
<<
"Failed open() with fd="
<<
std
::
to_string
(
fd
)
<<
" and errno="
<<
std
::
to_string
(
errno
)
<<
std
::
endl
;
}
int
write_rc
=
write
(
fd
,
(
void
*
)
data
,
sizeof
(
data
));
if
(
write_rc
!=
sizeof
(
data
))
{
std
::
cout
<<
"write() call returned wrong value rc="
<<
std
::
to_string
(
write_rc
)
<<
std
::
endl
;
}
else
{
int
write_rc
=
write
(
fd
,
(
void
*
)
data
,
sizeof
(
data
));
if
(
write_rc
!=
sizeof
(
data
))
{
std
::
cout
<<
"write() call returned wrong value rc="
<<
std
::
to_string
(
write_rc
)
<<
std
::
endl
;
}
else
{
std
::
cout
<<
"sys open / write ran without failure"
<<
std
::
endl
;
}
}
// fopen()
std
::
string
fopen_filepath
=
filepath
+
"_f
open
"
;
std
::
string
fopen_filepath
=
filepath
+
"_f
write
"
;
std
::
cout
<<
"Attempting to call fopen() on FAMFS for filename="
<<
fopen_filepath
<<
std
::
endl
;
FILE
*
stream_file
=
fopen
(
fopen_filepath
.
c_str
(),
"rwa+"
);
if
(
stream_file
==
NULL
)
{
std
::
cout
<<
"Failed fopen() with errno="
<<
std
::
to_string
(
errno
)
<<
std
::
endl
;
}
else
{
int
fwrite_rc
=
fwrite
((
void
*
)
data
,
1
,
sizeof
(
data
),
stream_file
);
if
(
fwrite_rc
!=
sizeof
(
data
))
{
std
::
cout
<<
"fwrite() call returned wrong value rc="
<<
std
::
to_string
(
fwrite_rc
)
<<
std
::
endl
;
}
else
{
std
::
cout
<<
"fopen / fwrite ran without failure"
<<
std
::
endl
;
}
}
int
fwrite_rc
=
fwrite
((
void
*
)
data
,
1
,
sizeof
(
data
),
stream_file
);
if
(
fwrite_rc
!=
sizeof
(
data
))
{
std
::
cout
<<
"write() call returned wrong value rc="
<<
std
::
to_string
(
write_rc
)
<<
std
::
endl
;
std
::
string
mmap_filepath
=
filepath
+
"_mmap"
;
std
::
cout
<<
"[MMAP] Attempting to call open() on FAMFS for filename="
<<
mmap_filepath
<<
std
::
endl
;
int
fd_mmap
=
open
(
mmap_filepath
.
c_str
(),
O_CREAT
|
O_RDWR
);
if
(
fd_mmap
<
0
)
{
std
::
cout
<<
"Failed open() with fd="
<<
std
::
to_string
(
fd_mmap
)
<<
" and errno="
<<
std
::
to_string
(
errno
)
<<
std
::
endl
;
}
else
{
auto
buf
=
mmap
(
NULL
,
length
,
PROT_WRITE
,
MAP_SHARED
,
fd_mmap
,
0
);
if
(
buf
==
MAP_FAILED
)
{
std
::
cout
<<
"[MMAP] Error! Memory mapping unsuccessful. errno="
<<
std
::
to_string
(
errno
)
<<
std
::
endl
;
}
else
{
memcpy
(
buf
,
data
,
length
);
if
(
munmap
(
buf
,
length
)
<
0
)
{
std
::
cout
<<
"[MMAP FAILED] errno="
<<
std
::
to_string
(
errno
)
<<
std
::
endl
;
}
else
{
std
::
cout
<<
"[MMAP SUCCESS]"
<<
std
::
endl
;
}
}
}
return
0
;
}
\ No newline at end of file
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