Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CSEP551
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Krishna Vinnakota
CSEP551
Commits
e0e7d07e
Commit
e0e7d07e
authored
17 years ago
by
rsc
Browse files
Options
Downloads
Patches
Plain Diff
test that fork fails gracefully
parent
5af5f6aa
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Makefile
+10
-4
10 additions, 4 deletions
Makefile
forktest.c
+54
-0
54 additions, 0 deletions
forktest.c
usertests.c
+39
-0
39 additions, 0 deletions
usertests.c
with
103 additions
and
4 deletions
Makefile
+
10
−
4
View file @
e0e7d07e
...
@@ -72,9 +72,9 @@ vectors.S : vectors.pl
...
@@ -72,9 +72,9 @@ vectors.S : vectors.pl
ULIB
=
ulib.o usys.o printf.o umalloc.o
ULIB
=
ulib.o usys.o printf.o umalloc.o
usertests
:
usertests.o $(ULIB)
_
usertests
:
usertests.o $(ULIB)
$(
LD
)
-N
-e
main
-Ttext
0
-o
usertests usertests.o
$(
ULIB
)
$(
LD
)
-N
-e
main
-Ttext
0
-o
_
usertests usertests.o
$(
ULIB
)
$(
OBJDUMP
)
-S
usertests
>
usertests.asm
$(
OBJDUMP
)
-S
_
usertests
>
usertests.asm
_echo
:
echo.o $(ULIB)
_echo
:
echo.o $(ULIB)
$(
LD
)
-N
-e
main
-Ttext
0
-o
_echo echo.o
$(
ULIB
)
$(
LD
)
-N
-e
main
-Ttext
0
-o
_echo echo.o
$(
ULIB
)
...
@@ -117,10 +117,16 @@ _zombie: zombie.o $(ULIB)
...
@@ -117,10 +117,16 @@ _zombie: zombie.o $(ULIB)
$(
LD
)
-N
-e
main
-Ttext
0
-o
_zombie zombie.o
$(
ULIB
)
$(
LD
)
-N
-e
main
-Ttext
0
-o
_zombie zombie.o
$(
ULIB
)
$(
OBJDUMP
)
-S
_zombie
>
zombie.asm
$(
OBJDUMP
)
-S
_zombie
>
zombie.asm
_forktest
:
forktest.o $(ULIB)
# forktest has less library code linked in - needs to be small
# in order to be able to max out the proc table.
$(
LD
)
-N
-e
main
-Ttext
0
-o
_forktest forktest.o ulib.o usys.o
$(
OBJDUMP
)
-S
_forktest
>
forktest.asm
mkfs
:
mkfs.c fs.h
mkfs
:
mkfs.c fs.h
cc
-o
mkfs mkfs.c
cc
-o
mkfs mkfs.c
UPROGS
=
usertests _echo _cat _init _kill _ln _ls _mkdir _rm _sh _zombie
UPROGS
=
_
usertests _echo _cat _init _kill _ln _ls _mkdir _rm _sh _zombie
_forktest
fs.img
:
mkfs README $(UPROGS)
fs.img
:
mkfs README $(UPROGS)
./mkfs fs.img README
$(
UPROGS
)
./mkfs fs.img README
$(
UPROGS
)
...
...
This diff is collapsed.
Click to expand it.
forktest.c
0 → 100644
+
54
−
0
View file @
e0e7d07e
// Test that fork fails gracefully.
// Tiny executable so that the limit can be filling the proc table.
#include
"types.h"
#include
"stat.h"
#include
"user.h"
void
printf
(
int
fd
,
char
*
s
,
...)
{
write
(
fd
,
s
,
strlen
(
s
));
}
void
forktest
(
void
)
{
int
n
,
pid
;
printf
(
1
,
"fork test
\n
"
);
for
(
n
=
0
;
n
<
1000
;
n
++
){
pid
=
fork
();
if
(
pid
<
0
)
break
;
if
(
pid
==
0
)
exit
();
}
if
(
n
==
1000
){
printf
(
1
,
"fork claimed to work 1000 times!
\n
"
);
exit
();
}
for
(;
n
>
0
;
n
--
){
if
(
wait
()
<
0
){
printf
(
1
,
"wait stopped early
\n
"
);
exit
();
}
}
if
(
wait
()
!=
-
1
){
printf
(
1
,
"wait got too many
\n
"
);
exit
();
}
printf
(
1
,
"fork test OK
\n
"
);
}
int
main
(
void
)
{
forktest
();
exit
();
}
This diff is collapsed.
Click to expand it.
usertests.c
+
39
−
0
View file @
e0e7d07e
...
@@ -1189,6 +1189,44 @@ iref(void)
...
@@ -1189,6 +1189,44 @@ iref(void)
printf
(
1
,
"empty file name OK
\n
"
);
printf
(
1
,
"empty file name OK
\n
"
);
}
}
// test that fork fails gracefully
// the forktest binary also does this, but it runs out of proc entries first.
// inside the bigger usertests binary, we run out of memory first.
void
forktest
(
void
)
{
int
n
,
pid
;
printf
(
1
,
"fork test
\n
"
);
for
(
n
=
0
;
n
<
1000
;
n
++
){
pid
=
fork
();
if
(
pid
<
0
)
break
;
if
(
pid
==
0
)
exit
();
}
if
(
n
==
1000
){
printf
(
1
,
"fork claimed to work 1000 times!
\n
"
);
exit
();
}
for
(;
n
>
0
;
n
--
){
if
(
wait
()
<
0
){
printf
(
1
,
"wait stopped early
\n
"
);
exit
();
}
}
if
(
wait
()
!=
-
1
){
printf
(
1
,
"wait got too many
\n
"
);
exit
();
}
printf
(
1
,
"fork test OK
\n
"
);
}
int
int
main
(
int
argc
,
char
*
argv
[])
main
(
int
argc
,
char
*
argv
[])
{
{
...
@@ -1223,6 +1261,7 @@ main(int argc, char *argv[])
...
@@ -1223,6 +1261,7 @@ main(int argc, char *argv[])
sharedfd
();
sharedfd
();
dirfile
();
dirfile
();
iref
();
iref
();
forktest
();
exectest
();
exectest
();
...
...
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