xref: /aosp_15_r20/external/rappor/client/cpp/run.sh (revision 2abb31345f6c95944768b5222a9a5ed3fc68cc00)
1#!/bin/bash
2#
3# Usage:
4#   ./run.sh <function name>
5
6set -o nounset
7set -o pipefail
8set -o errexit
9
10setup() {
11  # need libprotobuf-dev for headers to compile against.
12  sudo apt-get install protobuf-compiler libprotobuf-dev
13
14  # OpenSSL dev headers
15  sudo apt-get install libssl-dev
16}
17
18init() {
19  mkdir --verbose -p _tmp
20}
21
22rappor-sim() {
23  make _tmp/rappor_sim
24  _tmp/rappor_sim "$@"
25}
26
27protobuf-encoder-demo() {
28  make _tmp/protobuf_encoder_demo
29  _tmp/protobuf_encoder_demo "$@"
30}
31
32rappor-sim-demo() {
33  rappor-sim 16 2 128 0.25 0.75 0.5 <<EOF
34client,cohort,value
35c1,1,v1
36c1,1,v2
37c2,2,v3
38c2,2,v4
39EOF
40}
41
42empty-input() {
43  echo -n '' | rappor-sim 58 2 128 .025 0.75 0.5
44}
45
46# This outputs an HMAC and MD5 value.  Compare with Python/shell below.
47
48openssl-hash-impl-test() {
49  make _tmp/openssl_hash_impl_test
50  _tmp/openssl_hash_impl_test "$@"
51}
52
53test-hmac-sha256() {
54  #echo -n foo | sha256sum
55  python -c '
56import hashlib
57import hmac
58import sys
59
60secret = sys.argv[1]
61body = sys.argv[2]
62m = hmac.new(secret, body, digestmod=hashlib.sha256)
63print m.hexdigest()
64' "key" "value"
65}
66
67test-md5() {
68  echo -n value | md5sum
69}
70
71# -M: all headers
72# -MM: exclude system headers
73
74# -MF: file to write the dependencies to
75
76# -MD: like -M -MF
77# -MMD: -MD, but only system headers
78
79# -MP: workaround
80
81
82deps() {
83  # -MM seems like the one we want.
84  gcc -I _tmp -MM protobuf_encoder_test.cc unix_kernel_rand_impl.cc
85  #gcc -I _tmp -MMD -MP protobuf_encoder_test.cc unix_kernel_rand_impl.cc
86}
87
88count() {
89  wc -l *.h *.cc | sort -n
90}
91
92encoder-demo() {
93  make _tmp/encoder_demo && _tmp/encoder_demo
94}
95cpplint() {
96  ../../analysis/cpp/_tmp/cpplint.py "$@"
97}
98
99"$@"
100