# Generating the Binary

**URL:** <https://discuss.elastic.co/t/generating-the-binary/32526>\
**Category:** Beats\
**Tags:** packetbeat\
**Created:** [October 19, 2015, 7:20pm UTC](https://discuss.elastic.co/t/generating-the-binary/32526 "2015-10-19T19:20:36Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prerna\_Manaktala](https://avatars.discourse-cdn.com/v4/letter/p/9fc29f/32.png) [@Prerna\_Manaktala](https://discuss.elastic.co/u/Prerna_Manaktala)\
**Post date:** [October 19, 2015, 7:20pm UTC](https://discuss.elastic.co/t/generating-the-binary/32526/1 "2015-10-19T19:20:36Z")

</div>

Hello

I am new to golang and elasticsearch.  
I installed golang on mac and cloned the packetbeat repo.Trying to run the commang to execute step 1. Generating the Binary, but am unsuccesful.  
Can you please guide me as to how to generate the binary so that I can do a code coverage of my tests written in python.

---

<div class="post-metadata">

**Author:** ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)\
**Post date:** [October 19, 2015, 8:27pm UTC](https://discuss.elastic.co/t/generating-the-binary/32526/2 "2015-10-19T20:27:01Z")

</div>

Hi @Prerna_Manaktala, please follow the instructions listed in the [Developer Guide](https://www.elastic.co/guide/en/beats/packetbeat/master/_developer_guide_adding_a_new_protocol.html#_cloning_and_compiling) for compiling. It links to a guide to setting up Go and shows the commands for building.

After you can compile, you can generate a code coverage report that includes the python tests by running `make full-coverage`.

If you encounter a problem please include information about your environment and the error. And we'll try to help you out!

-Andrew

---

<div class="post-metadata">

**Author:** ![Prerna\_Manaktala](https://avatars.discourse-cdn.com/v4/letter/p/9fc29f/32.png) [@Prerna\_Manaktala](https://discuss.elastic.co/u/Prerna_Manaktala)\
**Post date:** [October 19, 2015, 9:00pm UTC](https://discuss.elastic.co/t/generating-the-binary/32526/3 "2015-10-19T21:00:19Z")

</div>

Thanks Andrew.  
I did above steps and am getting this error:  
$ make

# first make sure we have godep

go get [github.com/tools/godep](http://github.com/tools/godep)  
/Users/prernamanaktala/work/bin/godep go build

# [github.com/elastic/libbeat/outputs](http://github.com/elastic/libbeat/outputs)

Godeps/\_workspace/src/github.com/elastic/libbeat/outputs/tls.go:159: undefined: tls.TLS\_ECDHE\_RSA\_WITH\_AES\_256\_GCM\_SHA384  
Godeps/\_workspace/src/github.com/elastic/libbeat/outputs/tls.go:160: undefined: tls.TLS\_ECDHE\_ECDSA\_WITH\_AES\_256\_GCM\_SHA384  
godep: go exit status 2  
make: \*\*\* [packetbeat] Error 1

I did godep restore also which worked fine as I installed bazaar.  
But how to resolve the make error?  
My os is max osx Yosemite, version 10.10.5

---

<div class="post-metadata">

**Author:** ![steffens](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steffens/32/79630_2.png) [@steffens](https://discuss.elastic.co/u/steffens)\
**Post date:** [October 19, 2015, 10:02pm UTC](https://discuss.elastic.co/t/generating-the-binary/32526/4 "2015-10-19T22:02:36Z")

</div>

Hi,

have you installed go 1.4.\* ? For building you will need go 1.5.1 which adds these missing symbols.

---

<div class="post-metadata">

**Author:** ![Prerna\_Manaktala](https://avatars.discourse-cdn.com/v4/letter/p/9fc29f/32.png) [@Prerna\_Manaktala](https://discuss.elastic.co/u/Prerna_Manaktala)\
**Post date:** [October 19, 2015, 10:29pm UTC](https://discuss.elastic.co/t/generating-the-binary/32526/5 "2015-10-19T22:29:11Z")

</div>

Thanks Stephen, I was able to compile packetbeat after removing the older version of go on my system.  
But make fulltests gives this error:  
/Users/prernamanaktala/work/bin/godep go tool cover -html=./coverage/unit.cov -o coverage/unit.html  
make -C ./tests coverage  
make -C .. packetbeat.test  
make[2]: `packetbeat.test' is up to date.  
make -C .. env  
test -d env || virtualenv env \> /dev/null  
/bin/sh: virtualenv: command not found  
make[2]: \*\*\* [env/bin/activate] Error 127  
make[1]: \*\*\* [test] Error 2  
make: \*\*\* [full-coverage] Error 2

Is gotestcover generated in bin the binary file to be used in next steps?

---

<div class="post-metadata">

**Author:** ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)\
**Post date:** [October 19, 2015, 10:34pm UTC](https://discuss.elastic.co/t/generating-the-binary/32526/6 "2015-10-19T22:34:58Z")

</div>

> [@Prerna\_Manaktala](#):
>
> /bin/sh: virtualenv: command not found

It looks like you are missing the `virtualenv` command. See [Installation - virtualenv](https://virtualenv.pypa.io/en/latest/installation.html) regarding how to install it.

---

<div class="post-metadata">

**Author:** ![Prerna\_Manaktala](https://avatars.discourse-cdn.com/v4/letter/p/9fc29f/32.png) [@Prerna\_Manaktala](https://discuss.elastic.co/u/Prerna_Manaktala)\
**Post date:** [October 19, 2015, 11:27pm UTC](https://discuss.elastic.co/t/generating-the-binary/32526/7 "2015-10-19T23:27:42Z")

</div>

Thanks again. I am able to do make full-coverage now.  
But I still did not understand how I can run packetbeat with my python tests: [https://github.com/couchbase/testrunner/tree/master/pytests](https://github.com/couchbase/testrunner/tree/master/pytests) which I have in a local repo.  
Do I still need to run:go test -c -covermode=count -coverpkg ./...  
If yes then which folder do I run this command in?

I understand that I generated packetbeat.test which is used in further steps.

---

<div class="post-metadata">

**Author:** ![steffens](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steffens/32/79630_2.png) [@steffens](https://discuss.elastic.co/u/steffens)\
**Post date:** [October 19, 2015, 11:57pm UTC](https://discuss.elastic.co/t/generating-the-binary/32526/8 "2015-10-19T23:57:36Z")

</div>

packetbeat.test is a special packetbeat binary compiled with golang test framework included. Just try './packetbeat.test -h'. This binary basicaly includes all flags from 'go test' and packetbeat with 'go test' flags prefixed with '-test.'.

The system tests are based on python too. See tests/pbtests/packetbeay.py how packetbeat.test is run to create coverage information. At minimum you would require to run 'packetbeat.test -systemTest -test.coverprofile coverage.cov ' to run packetbeat with code coverage written to coverage.cov.

---

<div class="post-metadata">

**Author:** ![Prerna\_Manaktala](https://avatars.discourse-cdn.com/v4/letter/p/9fc29f/32.png) [@Prerna\_Manaktala](https://discuss.elastic.co/u/Prerna_Manaktala)\
**Post date:** [October 20, 2015, 4:11am UTC](https://discuss.elastic.co/t/generating-the-binary/32526/9 "2015-10-20T04:11:46Z")

</div>

./packetbeat.test -systemTest -c config.yml -test.coverprofile coverage.cov  
Failed to read config.yml: open config.yml: no such file or directory. Exiting.

config.yml is to be created by us?

output of ./packetbeat.test -h' is  
-I string  
file  
-N Disable actual publishing for testing  
-O Read packets one at a time (press Enter)  
-c string  
Configuration file (default "/etc/beat/beat.yml")  
-cpuprofile string  
Write cpu profile to file  
-d string  
Enable certain debug selectors  
-devices  
Print the list of devices and exit  
-dump string  
Write all captured packets to this libpcap file  
-e Output to stdout and disable syslog/file output  
-l int  
Loop file. 0 - loop forever (default 1)  
-memprofile string  
Write memory profile to this file  
-systemTest  
Set to true when running system tests  
-t Read packets as fast as possible, without sleeping  
-test  
Test configuration and exit.  
-test.bench string  
regular expression to select benchmarks to run  
-test.benchmem  
print memory allocations for benchmarks  
-test.benchtime duration  
approximate run time for each benchmark (default 1s)  
-test.blockprofile string  
write a goroutine blocking profile to the named file after execution  
-test.blockprofilerate int  
if \>= 0, calls runtime.SetBlockProfileRate() (default 1)  
-test.count n  
run tests and benchmarks n times (default 1)  
-test.coverprofile string  
write a coverage profile to the named file after execution  
-test.cpu string  
comma-separated list of number of CPUs to use for each test  
-test.cpuprofile string  
write a cpu profile to the named file during execution  
-test.memprofile string  
write a memory profile to the named file after execution  
-test.memprofilerate int  
if \>=0, sets runtime.MemProfileRate  
-test.outputdir string  
directory in which to write profiles  
-test.parallel int  
maximum test parallelism (default 8)  
-test.run string  
regular expression to select tests and examples to run  
-test.short  
run smaller test suite to save time  
-test.timeout duration  
if positive, sets an aggregate time limit for all tests  
-test.trace string  
write an execution trace to the named file after execution  
-test.v  
verbose: print additional output  
-v Log at INFO level  
-version  
Print version and exit  
-waitstop int  
Additional seconds to wait befor shutting down

Can I run ./packetbeat.test with some options/flags and give path to my python tests in a local folder?

---

<div class="post-metadata">

**Author:** ![ruflin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ruflin/32/3116_2.png) [@ruflin](https://discuss.elastic.co/u/ruflin)\
**Post date:** [October 20, 2015, 8:32am UTC](https://discuss.elastic.co/t/generating-the-binary/32526/10 "2015-10-20T08:32:07Z")

</div>

@Prerna_Manaktala Here you can see the exact commands that are used to run the system tests: [https://github.com/elastic/packetbeat/blob/master/tests/Makefile#L6](https://github.com/elastic/packetbeat/blob/master/tests/Makefile#L6)

```
make -C .. packetbeat.test
make -C .. env
. ../env/bin/activate && nosetests --processes=${PROCESSES} --process-timeout=$(TIMEOUT)

```

First the test binary is created, the the environment is setup and then nosetests is used to run the tests.

If you run full-coverage, your tests should be automatically picked up, run an added to the coverage report. If you only want to run a single test or test file, for simplicity you can temporarly edit the nosetests command in the Makefile and add a filter for the specific tests.

---

<div class="post-metadata">

**Author:** ![steffens](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/steffens/32/79630_2.png) [@steffens](https://discuss.elastic.co/u/steffens)\
**Post date:** [October 20, 2015, 11:54am UTC](https://discuss.elastic.co/t/generating-the-binary/32526/11 "2015-10-20T11:54:27Z")

</div>

@Prerna_Manaktala yes you have to configure packetbeat. What kind of tests do you want to run? You actively want to sniff packets or you want to drive your tests using a pcap?

For configuring and running packetbeat check out our docs: [https://www.elastic.co/guide/en/beats/packetbeat/master/index.html](https://www.elastic.co/guide/en/beats/packetbeat/master/index.html)

Our system tests do test packetbeat using pcap files. Check out [packetbeat.py](https://github.com/elastic/packetbeat/blob/master/tests/pbtests/packetbeat.py) to figure out how we start packetbeat. Our tests create run directories per test into which a sample configuration is build used to execute packetbeat.

Use '-c' on packetbeat.test to set the location of your configuration file.

---

<div class="post-metadata">

**Author:** ![Prerna\_Manaktala](https://avatars.discourse-cdn.com/v4/letter/p/9fc29f/32.png) [@Prerna\_Manaktala](https://discuss.elastic.co/u/Prerna_Manaktala)\
**Post date:** [October 20, 2015, 6:29pm UTC](https://discuss.elastic.co/t/generating-the-binary/32526/13 "2015-10-20T18:29:28Z")

</div>

Thanks , I want to run python tests in /usr/local/testrunner( git clone of [https://github.com/couchbase/testrunner/tree/master/pytests](https://github.com/couchbase/testrunner/tree/master/pytests) ) and my packetbeat.test is located in /Users/prernamanaktala/work/src/github.com/elastic/packetbeat which got generated after doing make full-coverage .My question is how can I know the code coverage in my python tests using packetbeat?  
[/quote]

---

<div class="post-metadata">

**Author:** ![Prerna\_Manaktala](https://avatars.discourse-cdn.com/v4/letter/p/9fc29f/32.png) [@Prerna\_Manaktala](https://discuss.elastic.co/u/Prerna_Manaktala)\
**Post date:** [October 20, 2015, 8:46pm UTC](https://discuss.elastic.co/t/generating-the-binary/32526/14 "2015-10-20T20:46:37Z")

</div>

Also is there an existing config.yml I can look at?

---

<div class="post-metadata">

**Author:** ![ruflin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ruflin/32/3116_2.png) [@ruflin](https://discuss.elastic.co/u/ruflin)\
**Post date:** [October 21, 2015, 7:03am UTC](https://discuss.elastic.co/t/generating-the-binary/32526/15 "2015-10-21T07:03:20Z")

</div>

@Prerna_Manaktala Here you can find the default config with all options inside: [https://github.com/elastic/packetbeat/blob/master/etc/packetbeat.yml](https://github.com/elastic/packetbeat/blob/master/etc/packetbeat.yml)

About generating the code coverage this blog post could also help: [https://www.elastic.co/blog/code-coverage-for-your-golang-system-tests](https://www.elastic.co/blog/code-coverage-for-your-golang-system-tests)

---

<div class="post-metadata">

**Author:** ![Prerna\_Manaktala](https://avatars.discourse-cdn.com/v4/letter/p/9fc29f/32.png) [@Prerna\_Manaktala](https://discuss.elastic.co/u/Prerna_Manaktala)\
**Post date:** [October 21, 2015, 7:36am UTC](https://discuss.elastic.co/t/generating-the-binary/32526/16 "2015-10-21T07:36:18Z")

</div>

Yes I used the default config file and the blog post above for code-coverage.  
But I am not able to make a connection between packetbeat , golang code: [https://github.com/couchbase/query](https://github.com/couchbase/query)  
and python tests written to test the golang code: [https://github.com/couchbase/testrunner](https://github.com/couchbase/testrunner).

---

<div class="post-metadata">

**Author:** ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)\
**Post date:** [October 21, 2015, 1:16pm UTC](https://discuss.elastic.co/t/generating-the-binary/32526/17 "2015-10-21T13:16:22Z")

</div>

There is no relationship between them unless you are using Packetbeat within couchbase/query. Are you? Otherwise, to get test coverage from your own application you do not need Packetbeat, instead you need to instrument your own application to generate code coverage metrics.

You can use the commands from Packetbeat as an example. This process is what is documented in the [blog post](https://www.elastic.co/blog/code-coverage-for-your-golang-system-tests) where Packetbeat is used as an example.

---

<div class="post-metadata">

**Author:** ![Prerna\_Manaktala](https://avatars.discourse-cdn.com/v4/letter/p/9fc29f/32.png) [@Prerna\_Manaktala](https://discuss.elastic.co/u/Prerna_Manaktala)\
**Post date:** [October 21, 2015, 4:19pm UTC](https://discuss.elastic.co/t/generating-the-binary/32526/18 "2015-10-21T16:19:44Z")

</div>

Yes I want to use packetbeat within couchbase/query. Thats right.  
But when I try to follow instructions in the blog. and run go test -c -covermode=count -coverpkg ./...  
inside couchbase/query and have main\_test.go in it as explained in blog,It gives me this error:  
./main\_test.go:19: undefined: main  
how should i start with packetbeat in couchbase/query?

---

<div class="post-metadata">

**Author:** ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)\
**Post date:** [October 21, 2015, 11:32pm UTC](https://discuss.elastic.co/t/generating-the-binary/32526/19 "2015-10-21T23:32:53Z")

</div>

Sorry @Prerna_Manaktala, I am having a difficult time understanding how you are trying to use Packetbeat. Could you explain a bit about how you are trying to use Packetbeat and what your goals are with this testing? This will help us answer your question. Thanks!

---

<div class="post-metadata">

**Author:** ![Prerna\_Manaktala](https://avatars.discourse-cdn.com/v4/letter/p/9fc29f/32.png) [@Prerna\_Manaktala](https://discuss.elastic.co/u/Prerna_Manaktala)\
**Post date:** [October 22, 2015, 12:48am UTC](https://discuss.elastic.co/t/generating-the-binary/32526/20 "2015-10-22T00:48:20Z")

</div>

Yes sure.  
I want to use packetbeat to get how much test coverage I have in my python tests in: /usr/local/couchbase/testrunner which is clone of [https://github.com/couchbase/testrunner/tuqquery](https://github.com/couchbase/testrunner/tuqquery). These tests are written for golang query code in /Users/prernamanaktala/work/src/github.com/couchbase/query which is clone of [https://github.com/couchbase/query](https://github.com/couchbase/query). My packetbeat code is in /Users/prernamanaktala/work/src/github.com/elasticsearch/packetbeat where I am able to do make full-coverage without changing the makefile and see unit.html and coverage.html.

I am able to change the makefile in packetbeat to point to my git repo:github.com/couchbase/query ,but when I do make full-coverage then, i get errors and packetbeat.test does not get generated.But unit.cov gets generated in coverage folder.  
prernamanaktala@couchbases-MacBook-Pro packetbeat (master) $ make full-coverage  
make coverage

# gotestcover is needed to fetch coverage for multiple packages

go get [github.com/pierrre/gotestcover](http://github.com/pierrre/gotestcover)  
mkdir -p coverage  
GOPATH=/Users/prernamanaktala/work/src/github.com/elastic/packetbeat/Godeps/\_workspace:/Users/prernamanaktala/work /Users/prernamanaktala/work/bin/gotestcover -coverprofile=./coverage/unit.cov -covermode=count [github.com/couchbase/query](http://github.com/couchbase/query)...  
test failed  
make[1]: \*\*\* [coverage] Error 1  
make: \*\*\* [full-coverage] Error 2

---

<div class="post-metadata">

**Author:** ![ruflin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ruflin/32/3116_2.png) [@ruflin](https://discuss.elastic.co/u/ruflin)\
**Post date:** [October 22, 2015, 7:17am UTC](https://discuss.elastic.co/t/generating-the-binary/32526/21 "2015-10-22T07:17:25Z")

</div>

@Prerna_Manaktala As @andrewkroh mentioned, there seems to be some confusion between the coverage report and packetbeat. Packetbeat is only the example project that is mentioned in the blog post to see how we implemented the coverage report. The coverage report and scripts itself are completely independent of packetbeat. So in case you want to implement a system coverage report for your project, you don't need packetbeat. You need to create the files mentioned in the blog post in your own project.

So if I understand you right now, what you are trying to do is getting a coverage report for `couchbase/query` binary by running your python tests stored in `couchbase/testrunner`? I assume so far these tests were run with the "default" binary generated from couchbase/query?

[Next page](https://discuss.elastic.co/t/generating-the-binary/32526.md?page=2)
