trace_processor: improve test framework and add kernel LMK tests

Change-Id: I099ccdc91bf62631126032b419bde94e1c9a7449
diff --git a/test/trace_processor/index b/test/trace_processor/index
index 36b8378..099dc72 100644
--- a/test/trace_processor/index
+++ b/test/trace_processor/index
@@ -12,13 +12,6 @@
 ../data/cpu_counters.pb b120487929.sql cpu_counters_b120487929.out
 ../data/memory_counters.pb b120278869_neg_ts_end.sql memory_counters_b120278869_neg_ts_end.out
 ../data/memory_counters.pb b120605557.sql memory_counters_b120605557.out
-# TODO(lalitm): this still doesn't work because we no longer add utid
-# args for memory counters (because they are keyed by upid).
-# ../data/memory_counters.pb smoke_args.sql memory_counters_smoke_args.out
-# ../data/memory_counters.pb counter_args_join.sql memory_counters_counter_args_join.out
-../data/memory_counters.pb args_string_filter_null.sql memory_counters_args_string_filter_null.out
-../data/memory_counters.pb args_string_is_null.sql memory_counters_args_string_is_null.out
-../data/memory_counters.pb args_string_is_not_null.sql memory_counters_args_string_is_not_null.out
 synth_1.py smoke.sql synth_1_smoke.out
 synth_1.py filter_sched.sql synth_1_filter_sched.out
 synth_1.py filter_counters.sql synth_1_filter_counters.out
@@ -27,6 +20,18 @@
 ../data/android_log.pb android_log_counts.sql android_log_counts.out
 ../data/android_log.pb android_log_msgs.sql android_log_msgs.out
 ../data/android_log_ring_buffer_mode.pb android_log_ring_buffer_mode.sql android_log_ring_buffer_mode.out
-../data/lmk_userspace.pb lmk.sql lmk_userspace_lmk.out
 ../data/mm_event.pb mm_event.sql mm_event.out
 ../data/process_stats_poll.pb oom_score_poll.sql process_stats_poll_oom_score.out
+
+# Test LMK handling
+kernel_lmk.py lmk.sql lmk_kernel_lmk.out
+../data/lmk_userspace.pb lmk.sql lmk_userspace_lmk.out
+
+# Test counters handling
+../data/memory_counters.pb args_string_filter_null.sql memory_counters_args_string_filter_null.out
+../data/memory_counters.pb args_string_is_null.sql memory_counters_args_string_is_null.out
+../data/memory_counters.pb args_string_is_not_null.sql memory_counters_args_string_is_not_null.out
+# TODO(lalitm): this still doesn't work because we no longer add utid
+# args for memory counters (because they are keyed by upid).
+# ../data/memory_counters.pb smoke_args.sql memory_counters_smoke_args.out
+# ../data/memory_counters.pb counter_args_join.sql memory_counters_counter_args_join.out
diff --git a/test/trace_processor/kernel_lmk.py b/test/trace_processor/kernel_lmk.py
new file mode 100644
index 0000000..959e798
--- /dev/null
+++ b/test/trace_processor/kernel_lmk.py
@@ -0,0 +1,32 @@
+#!/usr/bin/python
+# Copyright (C) 2018 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from os import sys, path
+
+sys.path.append(path.dirname(path.abspath(__file__)))
+import synth_common
+
+trace = synth_common.create_trace()
+trace.add_process_tree_packet()
+trace.add_process(pid=1, ppid=0, cmdline="init")
+trace.add_process(pid=2, ppid=1, cmdline="two_thread_process")
+trace.add_process(pid=4, ppid=1, cmdline="single_thread_process")
+trace.add_thread(tid=3, tgid=2, cmdline="two_thread_process")
+
+trace.add_ftrace_packet(0)
+trace.add_kernel_lmk(ts=100, tid=3)
+trace.add_kernel_lmk(ts=101, tid=4)
+
+print(trace.trace.SerializeToString())
diff --git a/test/trace_processor/lmk_kernel_lmk.out b/test/trace_processor/lmk_kernel_lmk.out
new file mode 100644
index 0000000..bebf6ea
--- /dev/null
+++ b/test/trace_processor/lmk_kernel_lmk.out
@@ -0,0 +1,3 @@
+"ts","pid"
+100,2
+101,4
diff --git a/test/trace_processor/synth_common.py b/test/trace_processor/synth_common.py
index 8d80433..bf665db 100644
--- a/test/trace_processor/synth_common.py
+++ b/test/trace_processor/synth_common.py
@@ -66,6 +66,12 @@
         cpufreq.state = freq
         cpufreq.cpu_id = cpu
 
+    def add_kernel_lmk(self, ts, tid):
+        ftrace = self.__add_ftrace_event(ts, tid)
+
+        lowmemory_kill = ftrace.lowmemory_kill
+        lowmemory_kill.pid = tid
+
     def add_process_tree_packet(self):
         self.packet = self.trace.packet.add()
 
diff --git a/tools/diff_test_trace_processor.py b/tools/diff_test_trace_processor.py
index 037f4e7..d7329c6 100755
--- a/tools/diff_test_trace_processor.py
+++ b/tools/diff_test_trace_processor.py
@@ -54,6 +54,8 @@
     stripped = line.strip()
     if stripped.startswith('#'):
       continue
+    elif not stripped:
+      continue
 
     [trace_fname, query_fname, expected_fname] = stripped.split(' ')