xref: /aosp_15_r20/external/rappor/tests/user_spec.py (revision 2abb31345f6c95944768b5222a9a5ed3fc68cc00)
1#!/usr/bin/python
2"""Print a test spec on stdout.
3
4Each line has parmaeters for a test case.  The regtest.sh shell script reads
5these lines and runs parallel processes.
6
7We use Python data structures so the test cases are easier to read and edit.
8"""
9
10import sys
11
12#
13# TEST CONFIGURATION
14#
15
16# For gen_sim_input.py
17INPUT_PARAMS = {
18    # distribution, num unique values, num clients, values per client
19    'exp-100k': ('exp', 100, 100000, 1),
20    'exp-1m': ('exp', 100, 1000000, 1),
21}
22
23# For rappor_sim.py
24# 'k, h, m, p, q, f' as in params file.
25RAPPOR_PARAMS = {
26    # Initial chrome params from 2014.
27    # NOTE: fastrand simulation only supports 64 bits!  Make sure to use the
28    # 'fast_counts' code path.
29    'chrome128': (128, 2, 128, 0.25, 0.75, 0.50),
30
31    # Chrome params from early 2015 -- changed to 8 bit reports.
32    'chrome8': (8, 2, 128, 0.25, 0.75, 0.50),
33
34    # Original demo params
35    'demo': (16, 2, 64, 0.5, 0.75, 0.5),
36}
37
38# For deriving candidates from true inputs.
39MAP_PARAMS = {
40    # 1. Number of extra candidates to add.
41    # 2. Candidate strings to remove from the map.  This FORCES false
42    # negatives, e.g. for common strings, since a string has to be in the map
43    # for RAPPOR to choose it.
44    'add-100': (100, []),
45    'add-1000': (1000, []),
46    'add-2000': (2000, []),
47    # also thrashes on 128 bits
48    'add-3000': (3000, []),
49    'add-10000': (10000, []),
50    'add-15000': (15000, []),  # approx number of candidates for eTLD+1
51    'add-100000': (100000, []),
52    'remove-top-2': (20, ['v1', 'v2']),
53}
54
55# test case name -> (input params name, RAPPOR params name, map params name)
56TEST_CASES = [
57    ('chrome128-100k-100', 'exp-100k', 'chrome128', 'add-100'),
58    ('chrome128-100k-1000', 'exp-100k', 'chrome128', 'add-1000'),
59    ('chrome128-100k-2000', 'exp-100k', 'chrome128', 'add-2000'),
60    ('chrome128-100k-3000', 'exp-100k', 'chrome128', 'add-3000'),
61    # 128 bits and 15k candidates fails on a machine with 8 GB memory.
62    # Lasso finishes with 7508 non-zero coefficients, and then allocation
63    # fails.  TODO: just take the highest ones?
64    #('chrome128-100k-15000', 'exp-100k', 'chrome128', 'add-15000'),
65    #('chrome128-100k-100000', 'exp-100k', 'chrome128', 'add-100000'),
66
67    # NOTE: Adding more candidates exercises LASSO
68    ('chrome8-100k-100', 'exp-100k', 'chrome8', 'add-100'),
69    ('chrome8-100k-1000', 'exp-100k', 'chrome8', 'add-1000'),
70    ('chrome8-100k-2000', 'exp-100k', 'chrome8', 'add-2000'),
71    ('chrome8-100k-3000', 'exp-100k', 'chrome8', 'add-3000'),
72    ('chrome8-100k-15000', 'exp-100k', 'chrome8', 'add-15000'),
73
74    # NOTE: This one takes too much memory!  More than 4 GB.  This is because
75    # Lasso gets a huge matrix (100,000).  We got 1564 non-zero coefficients.
76    ('chrome8-100k-100000', 'exp-100k', 'chrome8', 'add-100000'),
77
78    # What happens when the the candidates are missing top values?
79    ('chrome8-badcand', 'exp-100k', 'chrome8', 'remove-top-2'),
80
81    # TODO: Use chrome params with real map from Alexa 1M ?
82]
83
84#
85# END TEST CONFIGURATION
86#
87
88
89def main(argv):
90  rows = []
91  for test_case, input_name, rappor_name, map_name in TEST_CASES:
92    input_params = INPUT_PARAMS[input_name]
93    rappor_params = RAPPOR_PARAMS[rappor_name]
94    map_params = MAP_PARAMS[map_name]
95    row = tuple([test_case]) + input_params + rappor_params + map_params
96    rows.append(row)
97
98  for row in rows:
99    for cell in row:
100      if isinstance(cell, list):
101        if cell:
102          cell_str = '|'.join(cell)
103        else:
104          cell_str = 'NONE'  # we don't want an empty string
105      else:
106        cell_str = cell
107      print cell_str,  # print it with a space after it
108    print  # new line after row
109
110
111if __name__ == '__main__':
112  try:
113    main(sys.argv)
114  except RuntimeError, e:
115    print >>sys.stderr, 'FATAL: %s' % e
116    sys.exit(1)
117