|
Packit Service |
3482a6 |
/* Basic tests for pldd program.
|
|
Packit Service |
3482a6 |
Copyright (C) 2019 Free Software Foundation, Inc.
|
|
Packit Service |
3482a6 |
This file is part of the GNU C Library.
|
|
Packit Service |
3482a6 |
|
|
Packit Service |
3482a6 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit Service |
3482a6 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit Service |
3482a6 |
License as published by the Free Software Foundation; either
|
|
Packit Service |
3482a6 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit Service |
3482a6 |
|
|
Packit Service |
3482a6 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit Service |
3482a6 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
3482a6 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
3482a6 |
Lesser General Public License for more details.
|
|
Packit Service |
3482a6 |
|
|
Packit Service |
3482a6 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
3482a6 |
License along with the GNU C Library; if not, see
|
|
Packit Service |
3482a6 |
<http://www.gnu.org/licenses/>. */
|
|
Packit Service |
3482a6 |
|
|
Packit Service |
3482a6 |
#include <stdio.h>
|
|
Packit Service |
3482a6 |
#include <string.h>
|
|
Packit Service |
3482a6 |
#include <unistd.h>
|
|
Packit Service |
3482a6 |
#include <stdint.h>
|
|
Packit Service |
3482a6 |
#include <libgen.h>
|
|
Packit Service |
3482a6 |
#include <stdbool.h>
|
|
Packit Service |
3482a6 |
|
|
Packit Service |
3482a6 |
#include <array_length.h>
|
|
Packit Service |
3482a6 |
#include <gnu/lib-names.h>
|
|
Packit Service |
3482a6 |
|
|
Packit Service |
3482a6 |
#include <support/subprocess.h>
|
|
Packit Service |
3482a6 |
#include <support/capture_subprocess.h>
|
|
Packit Service |
3482a6 |
#include <support/check.h>
|
|
Packit Service |
3482a6 |
|
|
Packit Service |
3482a6 |
static void
|
|
Packit Service |
3482a6 |
target_process (void *arg)
|
|
Packit Service |
3482a6 |
{
|
|
Packit Service |
3482a6 |
pause ();
|
|
Packit Service |
3482a6 |
}
|
|
Packit Service |
3482a6 |
|
|
Packit Service |
3482a6 |
/* The test runs in a container because pldd does not support tracing
|
|
Packit Service |
3482a6 |
a binary started by the loader iself (as with testrun.sh). */
|
|
Packit Service |
3482a6 |
|
|
Packit Service |
3482a6 |
static int
|
|
Packit Service |
3482a6 |
do_test (void)
|
|
Packit Service |
3482a6 |
{
|
|
Packit Service |
3482a6 |
/* Create a copy of current test to check with pldd. */
|
|
Packit Service |
3482a6 |
struct support_subprocess target = support_subprocess (target_process, NULL);
|
|
Packit Service |
3482a6 |
|
|
Packit Service |
3482a6 |
/* Run 'pldd' on test subprocess. */
|
|
Packit Service |
3482a6 |
struct support_capture_subprocess pldd;
|
|
Packit Service |
3482a6 |
{
|
|
Packit Service |
3482a6 |
/* Three digits per byte plus null terminator. */
|
|
Packit Service |
3482a6 |
char pid[3 * sizeof (uint32_t) + 1];
|
|
Packit Service |
3482a6 |
snprintf (pid, array_length (pid), "%d", target.pid);
|
|
Packit Service |
3482a6 |
|
|
Packit Service |
3482a6 |
const char prog[] = "/usr/bin/pldd";
|
|
Packit Service |
3482a6 |
|
|
Packit Service |
3482a6 |
pldd = support_capture_subprogram (prog,
|
|
Packit Service |
3482a6 |
(char *const []) { (char *) prog, pid, NULL });
|
|
Packit Service |
3482a6 |
|
|
Packit Service |
3482a6 |
support_capture_subprocess_check (&pldd, "pldd", 0, sc_allow_stdout);
|
|
Packit Service |
3482a6 |
}
|
|
Packit Service |
3482a6 |
|
|
Packit Service |
3482a6 |
/* Check 'pldd' output. The test is expected to be linked against only
|
|
Packit Service |
3482a6 |
loader and libc. */
|
|
Packit Service |
3482a6 |
{
|
|
Packit Service |
3482a6 |
pid_t pid;
|
|
Packit Service |
3482a6 |
char buffer[512];
|
|
Packit Service |
3482a6 |
#define STRINPUT(size) "%" # size "s"
|
|
Packit Service |
3482a6 |
|
|
Packit Service |
3482a6 |
FILE *out = fmemopen (pldd.out.buffer, pldd.out.length, "r");
|
|
Packit Service |
3482a6 |
TEST_VERIFY (out != NULL);
|
|
Packit Service |
3482a6 |
|
|
Packit Service |
3482a6 |
/* First line is in the form of <pid>: <full path of executable> */
|
|
Packit Service |
3482a6 |
TEST_COMPARE (fscanf (out, "%u: " STRINPUT (512), &pid, buffer), 2);
|
|
Packit Service |
3482a6 |
|
|
Packit Service |
3482a6 |
TEST_COMPARE (pid, target.pid);
|
|
Packit Service |
3482a6 |
TEST_COMPARE (strcmp (basename (buffer), "tst-pldd"), 0);
|
|
Packit Service |
3482a6 |
|
|
Packit Service |
3482a6 |
/* It expects only one loader and libc loaded by the program. */
|
|
Packit Service |
3482a6 |
bool interpreter_found = false, libc_found = false;
|
|
Packit Service |
3482a6 |
while (fgets (buffer, array_length (buffer), out) != NULL)
|
|
Packit Service |
3482a6 |
{
|
|
Packit Service |
3482a6 |
/* Ignore vDSO. */
|
|
Packit Service |
3482a6 |
if (buffer[0] != '/')
|
|
Packit Service |
3482a6 |
continue;
|
|
Packit Service |
3482a6 |
|
|
Packit Service |
3482a6 |
/* Remove newline so baseline (buffer) can compare against the
|
|
Packit Service |
3482a6 |
LD_SO and LIBC_SO macros unmodified. */
|
|
Packit Service |
3482a6 |
if (buffer[strlen(buffer)-1] == '\n')
|
|
Packit Service |
3482a6 |
buffer[strlen(buffer)-1] = '\0';
|
|
Packit Service |
3482a6 |
|
|
Packit Service |
3482a6 |
if (strcmp (basename (buffer), LD_SO) == 0)
|
|
Packit Service |
3482a6 |
{
|
|
Packit Service |
3482a6 |
TEST_COMPARE (interpreter_found, false);
|
|
Packit Service |
3482a6 |
interpreter_found = true;
|
|
Packit Service |
3482a6 |
continue;
|
|
Packit Service |
3482a6 |
}
|
|
Packit Service |
3482a6 |
|
|
Packit Service |
3482a6 |
if (strcmp (basename (buffer), LIBC_SO) == 0)
|
|
Packit Service |
3482a6 |
{
|
|
Packit Service |
3482a6 |
TEST_COMPARE (libc_found, false);
|
|
Packit Service |
3482a6 |
libc_found = true;
|
|
Packit Service |
3482a6 |
continue;
|
|
Packit Service |
3482a6 |
}
|
|
Packit Service |
3482a6 |
}
|
|
Packit Service |
3482a6 |
TEST_COMPARE (interpreter_found, true);
|
|
Packit Service |
3482a6 |
TEST_COMPARE (libc_found, true);
|
|
Packit Service |
3482a6 |
|
|
Packit Service |
3482a6 |
fclose (out);
|
|
Packit Service |
3482a6 |
}
|
|
Packit Service |
3482a6 |
|
|
Packit Service |
3482a6 |
support_capture_subprocess_free (&pldd);
|
|
Packit Service |
3482a6 |
support_process_terminate (&target);
|
|
Packit Service |
3482a6 |
|
|
Packit Service |
3482a6 |
return 0;
|
|
Packit Service |
3482a6 |
}
|
|
Packit Service |
3482a6 |
|
|
Packit Service |
3482a6 |
#include <support/test-driver.c>
|