# ![](./csmith.png)
## About
Csmith is a random generator of C programs. It's primary purpose is to find
compiler bugs with random programs, using differential testing as the
test oracle.
Csmith can be used outside of the field of compiler testing.
If your application needs a test suite of C programs and you don't bother to
write them, feel free to give Csmith a try.
Csmith outputs C programs free of undefined behaviors (believe us, that's
not trivial), and the statistics of each generated program.
## Install Csmith
You can install Csmith from tarballs downloaded from [here (coming soon)](doc/releases.md),
or you can build it from the source. The following commands
apply to Ubuntu.
```
git clone https://github.com/csmith-project/csmith.git
cd csmith
sudo apt install g++ cmake m4
cmake -DCMAKE_INSTALL_PREFIX=<INSTALL-PREFIX> .
make && make install
```
Please see specific instructions for [building on
Windows](doc/build-csmith-on-windows.md).
## Use Csmith
Suppose Csmith is installed to `$HOME/csmith` locally. You can simply
generate, compile, and execute a test case by:
```bash
export PATH=$PATH:$HOME/csmith/bin
csmith > random1.c
gcc random1.c -I$HOME/csmith/include -o random1
./random1
```
To add differential testing into the picture, we need to install another
compiler, e.g., another version of **gcc** or **clang**. And repeat the process of:
```
csmith > random2.c
gcc random2.c -I$HOME/csmith/include -o random2_gcc
clang random2.c -I$HOME/csmith/include -o random2_clang
./random2_gcc > gcc_output.txt
./random2_clang > clang_output.txt
```
If there is any difference in `gcc_output.txt` and `clang_output.txt`,
aha, you have found a bug in either **gcc** or **clang**, or, in the
unlikely case, a bug in Csmith itself.
You could write scripts in your favorite language to repeat
the above process to amplify the power of random differential testing.
The generate programs might contain infinite loops. The best practice is
to apply timeout to their executions.
Use `csmith -h` or `csmith -hh` to see lists of command line options that you
can pass to Csmith and customize the random generation.
Here is a slightly outdated but still relevant document about
[using Csmith for compiler testing](http://embed.cs.utah.edu/csmith/using.html).
## History
Csmith was originally developed at the University of Utah by:
* [Xuejun Yang](https://github.com/jxyang)
* [Yang Chen](https://github.com/chenyang78)
* [Eric Eide](https://github.com/eeide)
* [John Regehr](https://github.com/regehr)
as part of a research project on compiler testing. The research is best
summarized by our paper
[Finding and Understanding Bugs in C Compilers](https://www.cs.utah.edu/~regehr/papers/pldi11-preprint.pdf).
More research info can be found
[here](http://embed.cs.utah.edu/csmith/).
Csmith was open sourced in 2009. We try to keep maintaining it as an open source
project using discretionary times. As much, the response to bug reports or
feature requests might be delayed.
## Community
Please use github [issues](https://github.com/csmith-project/csmith/issues/new)
to report bugs or suggestions.
We have a mailing list for discussing Csmith.
Please visit [here](http://www.flux.utah.edu/mailman/listinfo/csmith-dev) to subscribe.
没有合适的资源?快使用搜索试试~ 我知道了~
Csmith, a random generator of C programs.zip
共225个文件
h:92个
cpp:71个
txt:8个
需积分: 5 0 下载量 179 浏览量
2024-01-05
14:16:44
上传
评论
收藏 518KB ZIP 举报
温馨提示
Csmith, a random generator of C programs
资源推荐
资源详情
资源评论
收起资源包目录
Csmith, a random generator of C programs.zip (225个子文件)
AUTHORS 447B
build_compiler 6KB
gonzalez.c 10KB
lev.c 3KB
volatile_runtime.c 2KB
_rand48.c 1KB
srand48.c 859B
lrand48.c 623B
ChangeLog 9KB
GetGitRevisionDescription.cmake 4KB
COPYING 1KB
Type.cpp 53KB
VariableSelector.cpp 48KB
RandomProgramGenerator.cpp 48KB
Variable.cpp 35KB
Probabilities.cpp 30KB
Statement.cpp 26KB
Function.cpp 25KB
FactPointTo.cpp 25KB
ArrayVariable.cpp 23KB
FactMgr.cpp 22KB
Block.cpp 21KB
FunctionInvocation.cpp 20KB
CGOptions.cpp 19KB
CVQualifiers.cpp 19KB
Bookkeeper.cpp 18KB
CGContext.cpp 17KB
StatementAssign.cpp 16KB
StatementFor.cpp 15KB
Constant.cpp 15KB
FunctionInvocationUser.cpp 14KB
DepthSpec.cpp 14KB
StatementGoto.cpp 13KB
Effect.cpp 13KB
FunctionInvocationBinary.cpp 12KB
DFSRndNumGenerator.cpp 12KB
Lhs.cpp 11KB
OutputMgr.cpp 10KB
StatementArrayOp.cpp 10KB
Expression.cpp 9KB
FactUnion.cpp 8KB
SafeOpFlags.cpp 8KB
Fact.cpp 8KB
ExpressionVariable.cpp 8KB
StatementIf.cpp 8KB
FunctionInvocationUnary.cpp 7KB
DefaultOutputMgr.cpp 7KB
ExpressionFuncall.cpp 7KB
StringUtils.cpp 6KB
util.cpp 5KB
DefaultRndNumGenerator.cpp 5KB
RandomNumber.cpp 5KB
PartialExpander.cpp 5KB
random.cpp 5KB
ExtensionMgr.cpp 4KB
CoverageTestExtension.cpp 4KB
StatementExpr.cpp 4KB
StatementBreak.cpp 4KB
StatementReturn.cpp 4KB
StatementContinue.cpp 4KB
ExpressionAssign.cpp 4KB
ExpressionComma.cpp 4KB
AbsExtension.cpp 4KB
platform.cpp 4KB
AbsRndNumGenerator.cpp 4KB
AbsProgramGenerator.cpp 3KB
DFSOutputMgr.cpp 3KB
DFSProgramGenerator.cpp 3KB
CrestExtension.cpp 3KB
KleeExtension.cpp 3KB
DefaultProgramGenerator.cpp 3KB
VectorFilter.cpp 3KB
LinearSequence.cpp 2KB
Filter.cpp 2KB
CompatibleChecker.cpp 2KB
CFGEdge.cpp 2KB
SequenceFactory.cpp 2KB
Finalization.cpp 2KB
ExtensionValue.cpp 2KB
Attribute.cpp 2KB
Error.cpp 2KB
Sequence.cpp 2KB
evaluate_program 15KB
.gitattributes 38B
.gitignore 549B
.gitignore 155B
.gitignore 106B
CGOptions.h 18KB
Probabilities.h 11KB
Type.h 11KB
Variable.h 9KB
VariableSelector.h 8KB
stdint.h 7KB
Enumerator.h 7KB
Statement.h 6KB
CGContext.h 6KB
safe_abbrev.h 6KB
FactMgr.h 6KB
DepthSpec.h 6KB
FactPointTo.h 6KB
共 225 条
- 1
- 2
- 3
资源评论
Lei宝啊
- 粉丝: 1979
- 资源: 1330
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功