|
1 | 1 | import glob
|
2 | 2 | import json
|
| 3 | +import os |
3 | 4 | import os.path
|
4 | 5 | import shutil
|
5 | 6 | import subprocess
|
6 | 7 | import tempfile
|
| 8 | +import time |
7 | 9 | import unittest
|
8 | 10 | from contextlib import contextmanager
|
9 | 11 | from enum import Enum
|
@@ -237,6 +239,63 @@ def test_no_args_shows_help(self):
|
237 | 239 | self.expectReturncode(proc, ExitStatus.USAGE_ERROR)
|
238 | 240 | self.assertIn(b"usage: ", proc.stdout)
|
239 | 241 |
|
| 242 | + def test_remove_mappings(self): |
| 243 | + with subprocess.Popen( |
| 244 | + f"{self.binary_path} 100", |
| 245 | + stdout=subprocess.PIPE, |
| 246 | + stderr=subprocess.PIPE, |
| 247 | + text=True, |
| 248 | + shell=True, |
| 249 | + ) as target_proc: |
| 250 | + pid = target_proc.pid |
| 251 | + |
| 252 | + # The sleep is unfortunate but it allows the segments to get |
| 253 | + # established in the target process. |
| 254 | + time.sleep(2) |
| 255 | + |
| 256 | + numsegs = subprocess.run( |
| 257 | + f"cat /proc/{pid}/maps | wc -l", |
| 258 | + shell=True, |
| 259 | + capture_output=True, |
| 260 | + check=True, |
| 261 | + ) |
| 262 | + beforeSegs = int(numsegs.stdout.decode("ascii")) |
| 263 | + |
| 264 | + proc = subprocess.run( |
| 265 | + f"{self.oid} --script {self.script()} -t 1 --pid {pid}", |
| 266 | + shell=True, |
| 267 | + stdout=subprocess.PIPE, |
| 268 | + stderr=subprocess.PIPE, |
| 269 | + ) |
| 270 | + self.expectReturncode(proc, ExitStatus.SUCCESS) |
| 271 | + |
| 272 | + numsegs = subprocess.run( |
| 273 | + f"cat /proc/{pid}/maps | wc -l", |
| 274 | + shell=True, |
| 275 | + capture_output=True, |
| 276 | + check=True, |
| 277 | + ) |
| 278 | + afterSegs = int(numsegs.stdout.decode("ascii")) |
| 279 | + self.assertEqual(beforeSegs, afterSegs - 2) |
| 280 | + |
| 281 | + # remove both the text and data segments |
| 282 | + proc = subprocess.run( |
| 283 | + f"{self.oid} -r --pid {pid}", |
| 284 | + shell=True, |
| 285 | + stdout=subprocess.PIPE, |
| 286 | + stderr=subprocess.PIPE, |
| 287 | + ) |
| 288 | + self.expectReturncode(proc, ExitStatus.SUCCESS) |
| 289 | + |
| 290 | + numsegs = subprocess.run( |
| 291 | + f"cat /proc/{pid}/maps | wc -l", |
| 292 | + shell=True, |
| 293 | + capture_output=True, |
| 294 | + check=True, |
| 295 | + ) |
| 296 | + afterRemSegs = int(numsegs.stdout.decode("ascii")) |
| 297 | + self.assertEqual(beforeSegs, afterRemSegs) |
| 298 | + |
240 | 299 | def test_metrics_data_is_generated(self):
|
241 | 300 | with self.spawn_oid(self.script()) as proc:
|
242 | 301 | self.expectReturncode(proc, ExitStatus.SUCCESS)
|
|
0 commit comments