Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Drung <[email protected]>
  • Loading branch information
bdrung committed Apr 23, 2021
0 parents commit 9f0492e
Show file tree
Hide file tree
Showing 11 changed files with 486 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/*.1
/divide-by-zero
/leak-memory
/seg-fault
15 changes: 15 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
chaos-marmosets is licensed under ISC:

Copyright (C) 2010-2021, Benjamin Drung <[email protected]>

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
42 changes: 42 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
VERSION = 0.1

CC ?= gcc
CFLAGS ?= -std=gnu99 -Wall -Wextra -Werror -O3
PREFIX ?= /usr

all: divide-by-zero leak-memory seg-fault doc

divide-by-zero: divide-by-zero.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $^

leak-memory: leak-memory.c
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ $^

clean:
rm -f divide-by-zero leak-memory seg-fault *.1

%.1: %.1.md
pandoc -s -t man $^ -o $@

doc: divide-by-zero.1 leak-memory.1 seg-fault.1

install: divide-by-zero leak-memory seg-fault
install -D -m 755 divide-by-zero $(DESTDIR)$(PREFIX)/bin/divide-by-zero
install -D -m 755 leak-memory $(DESTDIR)$(PREFIX)/bin/leak-memory
install -D -m 755 seg-fault $(DESTDIR)$(PREFIX)/bin/seg-fault
install -D -m 644 divide-by-zero.1 $(DESTDIR)$(PREFIX)/share/man/man1/divide-by-zero.1
install -D -m 644 leak-memory.1 $(DESTDIR)$(PREFIX)/share/man/man1/leak-memory.1
install -D -m 644 seg-fault.1 $(DESTDIR)$(PREFIX)/share/man/man1/seg-fault.1

version:
@echo $(VERSION)

%.asc: %
gpg --armor --batch --detach-sign --yes --output $@ $^

%.tar.xz: divide-by-zero.1.md divide-by-zero.c leak-memory.1.md leak-memory.c LICENSE Makefile NEWS README.md seg-fault.1.md seg-fault.c
tar -cJf $@ --transform 's,^,chaos-marmosets-$(VERSION)/,' $^

dist: chaos-marmosets-$(VERSION).tar.xz chaos-marmosets-$(VERSION).tar.xz.asc

.PHONY: all clean dist doc install version
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
chaos-marmosets 0.1 (2021-04-23)

* Initial release
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
Chaos marmosets
===============

This project contains small programs that behave badly. They can be used for
[chaos engineering](https://en.wikipedia.org/wiki/Chaos_engineering) to test
the system behavior and the infrastructure setup for those cases.

divide-by-zero
--------------

This program tries to divide a number by zero. It will immediately exit with
signal 4 (SIGILL). This program is useful to test the process core dump
configuration. See the Linux kernel sysctl setting `kernel.core_pattern` and
`fs.suid_dumpable` for more information. In case of using a bug reporting
system like [apport](https://wiki.ubuntu.com/Apport), this program allows
testing reporting the crash and retracing it.

leak-memory
-----------

This program will eat your memory like Obelix eats cake until it will
eventually trigger the out of memory (OOM) killer. This program is useful to
test configured cgroups memory limitations and the OOM killer behavior.
leak-memory will use `malloc` to allocate 1 MiB blocks of memory in a loop
until the given maximum memory size (by default 42 TiB) is reached. The
allocated memory blocks will be filled with data to avoid optimization
preventing the leak. The program will report its progress to make it easy to
spot when leak-memory hits the OOM killer.

seg-fault
---------

This program tries write to address zero and will trigger a segmentation fault
(signal 11). It is useful to test the process core dump configuration. See the
Linux kernel sysctl setting `kernel.core_pattern` and `fs.suid_dumpable` for
more information. In case of using a bug reporting system like
[apport](https://wiki.ubuntu.com/Apport), this program allows testing reporting
the crash and retracing it.

Contributing
============

Contributions are welcome. Please follow
[How to Write a Git Commit Message](https://chris.beams.io/posts/git-commit/)
for writing good commit messages.

Creating releases
=================

To create a release, increase the version in `Makefile`, document the
noteworthy changes in `NEWS`, commit and tag the release:

```
git commit -s -m "Release chaos-marmosets $(make version)" Makefile NEWS
git tag v$(make version)
```

The xz-compressed release tarball can be generated by running:
```
make dist
```
34 changes: 34 additions & 0 deletions divide-by-zero.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
date: 2021-04-23
footer: chaos-marmosets
header: "divide-by-zero's Manual"
layout: page
license: 'Licensed under the ISC license'
section: 1
title: DIVIDE-BY-ZERO
---

# NAME

divide-by-zero - try to divide a number by zero and crash

# SYNOPSIS

**divide-by-zero**

# DESCRIPTION

**divide-by-zero** tries to divide a number by zero. It will immediately exit
with signal 4 (SIGILL). This program is useful to test the process core dump
configuration. See the Linux kernel sysctl setting *kernel.core_pattern* and
*fs.suid_dumpable* for more information. In case of using a bug reporting
system like apport, this program allows testing reporting the crash and
retracing it.

# OPTIONS

This program takes no options.

# AUTHOR

Benjamin Drung <[email protected]>
35 changes: 35 additions & 0 deletions divide-by-zero.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2021, Benjamin Drung <[email protected]>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#include <stdio.h>
#include <stdlib.h>

int divide_by_zero() {
int zero = 0;

return 42 / zero;
}

int main(int argc, char *argv[]) {
if(argc != 1) {
fprintf(stderr, "Usage: %s\n", argv[0]);
return EXIT_FAILURE;
}

printf("42 / 0 = %i\n", divide_by_zero());

return EXIT_SUCCESS;
}
38 changes: 38 additions & 0 deletions leak-memory.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
date: 2021-04-23
footer: chaos-marmosets
header: "leak-memory's Manual"
layout: page
license: 'Licensed under the ISC license'
section: 1
title: LEAK-MEMORY
---

# NAME

leak-memory - eat your memory like Obelix eats cake

# SYNOPSIS

**leak-memory** [*max_memory_size*]

# DESCRIPTION

**leak-memory** will eat your memory like Obelix eats cake until it will
eventually trigger the out of memory (OOM) killer. This program is useful to
test configured cgroups memory limitations and the OOM killer behavior.

**leak-memory** will use *malloc* to allocate 1 MiB blocks of memory in a loop
until the given maximum memory size (by default 42 TiB) is reached. The
allocated memory blocks will be filled with data to avoid optimization
preventing the leak. The program will report its progress to make it easy to
spot when **leak-memory** hits the OOM killer.

# OPTIONS

*max_memory_size*
: Maximum memory size to allocate in MiB (42 TiB by default)

# AUTHOR

Benjamin Drung <[email protected]>
Loading

0 comments on commit 9f0492e

Please sign in to comment.