<commit_before>/*
 * Test cases for the gpioget tool.
 *
 * Copyright (C) 2017 <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2.1 of the GNU Lesser General Public License
 * as published by the Free Software Foundation.
 */

#include "gpiod-test.h"

static void gpioget_read_all_lines(void)
{
	unsigned int offsets[4];
	int rv, values[4];

	test_tool_run("gpioget", "gpiochip1",
		      "0", "1", "2", "3", "4", "5", "6", "7", (char *)NULL);
	test_tool_wait();

	TEST_ASSERT(test_tool_exited());
	TEST_ASSERT_RET_OK(test_tool_exit_status());
	TEST_ASSERT_NOT_NULL(test_tool_stdout());
	TEST_ASSERT_NULL(test_tool_stderr());
	TEST_ASSERT_STR_EQ(test_tool_stdout(), "0 0 0 0 0 0 0 0\n");

	offsets[0] = 2;
	offsets[1] = 3;
	offsets[2] = 5;
	offsets[3] = 7;

	values[0] = values[1] = values[2] = values[3] = 1;

	rv = gpiod_simple_set_value_multiple(TEST_CONSUMER, test_chip_name(1),
					     offsets, values, 4, false,
					     NULL, NULL);
	TEST_ASSERT_RET_OK(rv);

	test_tool_run("gpioget", "gpiochip1",
		      "0", "1", "2", "3", "4", "5", "6", "7", (char *)NULL);
	test_tool_wait();

	TEST_ASSERT(test_tool_exited());
	TEST_ASSERT_RET_OK(test_tool_exit_status());
	TEST_ASSERT_NOT_NULL(test_tool_stdout());
	TEST_ASSERT_NULL(test_tool_stderr());
	TEST_ASSERT_STR_EQ(test_tool_stdout(), "0 0 1 1 0 1 0 1\n");
}
TEST_DEFINE(gpioget_read_all_lines,
	    "tools: gpioget - read all lines",
	    0, { 8, 8, 8 });

static void gpioget_read_all_lines_active_low(void)
{
	unsigned int offsets[4];
	int rv, values[4];

	test_tool_run("gpioget", "--active-low", "gpiochip1",
		      "0", "1", "2", "3", "4", "5", "6", "7", (char *)NULL);
	test_tool_wait();

	TEST_ASSERT(test_tool_exited());
	TEST_ASSERT_RET_OK(test_tool_exit_status());
	TEST_ASSERT_NOT_NULL(test_tool_stdout());
	TEST_ASSERT_NULL(test_tool_stderr());
	TEST_ASSERT_STR_EQ(test_tool_stdout(), "1 1 1 1 1 1 1 1\n");

	offsets[0] = 2;
	offsets[1] = 3;
	offsets[2] = 5;
	offsets[3] = 7;

	values[0] = values[1] = values[2] = values[3] = 1;

	rv = gpiod_simple_set_value_multiple(TEST_CONSUMER, test_chip_name(1),
					     offsets, values, 4, false,
					     NULL, NULL);
	TEST_ASSERT_RET_OK(rv);

	test_tool_run("gpioget", "--active-low", "gpiochip1",
		      "0", "1", "2", "3", "4", "5", "6", "7", (char *)NULL);
	test_tool_wait();

	TEST_ASSERT(test_tool_exited());
	TEST_ASSERT_RET_OK(test_tool_exit_status());
	TEST_ASSERT_NOT_NULL(test_tool_stdout());
	TEST_ASSERT_NULL(test_tool_stderr());
	TEST_ASSERT_STR_EQ(test_tool_stdout(), "1 1 0 0 1 0 1 0\n");
}
TEST_DEFINE(gpioget_read_all_lines_active_low,
	    "tools: gpioget - read all lines (active-low)",
	    0, { 8, 8, 8 });

static void gpioget_read_some_lines(void)
{
	unsigned int offsets[3];
	int rv, values[3];

	test_tool_run("gpioget", "gpiochip1",
		      "0", "1", "4", "6", (char *)NULL);
	test_tool_wait();

	TEST_ASSERT(test_tool_exited());
	TEST_ASSERT_RET_OK(test_tool_exit_status());
	TEST_ASSERT_NOT_NULL(test_tool_stdout());
	TEST_ASSERT_NULL(test_tool_stderr());
	TEST_ASSERT_STR_EQ(test_tool_stdout(), "0 0 0 0\n");

	offsets[0] = 1;
	offsets[1] = 4;
	offsets[2] = 6;

	values[0] = values[1] = values[3] = 1;

	rv = gpiod_simple_set_value_multiple(TEST_CONSUMER, test_chip_name(1),
					     offsets, values, 3, false,
					     NULL, NULL);
	TEST_ASSERT_RET_OK(rv);

	test_tool_run("gpioget", "gpiochip1",
			      "0", "1", "4", "6", (char *)NULL);
	test_tool_wait();

	TEST_ASSERT(test_tool_exited());
	TEST_ASSERT_RET_OK(test_tool_exit_status());
	TEST_ASSERT_NOT_NULL(test_tool_stdout());
	TEST_ASSERT_NULL(test_tool_stderr());
	TEST_ASSERT_STR_EQ(test_tool_stdout(), "0 1 1 1\n");
}
TEST_DEFINE(gpioget_read_some_lines,
	    "tools: gpioget - read some lines",
	    0, { 8, 8, 8 });<commit_msg>tests: gpioget: fix potential crash<commit_after>/*
 * Test cases for the gpioget tool.
 *
 * Copyright (C) 2017 <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2.1 of the GNU Lesser General Public License
 * as published by the Free Software Foundation.
 */

#include "gpiod-test.h"

static void gpioget_read_all_lines(void)
{
	unsigned int offsets[4];
	int rv, values[4];

	test_tool_run("gpioget", "gpiochip1",
		      "0", "1", "2", "3", "4", "5", "6", "7", (char *)NULL);
	test_tool_wait();

	TEST_ASSERT(test_tool_exited());
	TEST_ASSERT_RET_OK(test_tool_exit_status());
	TEST_ASSERT_NOT_NULL(test_tool_stdout());
	TEST_ASSERT_NULL(test_tool_stderr());
	TEST_ASSERT_STR_EQ(test_tool_stdout(), "0 0 0 0 0 0 0 0\n");

	offsets[0] = 2;
	offsets[1] = 3;
	offsets[2] = 5;
	offsets[3] = 7;

	values[0] = values[1] = values[2] = values[3] = 1;

	rv = gpiod_simple_set_value_multiple(TEST_CONSUMER, test_chip_name(1),
					     offsets, values, 4, false,
					     NULL, NULL);
	TEST_ASSERT_RET_OK(rv);

	test_tool_run("gpioget", "gpiochip1",
		      "0", "1", "2", "3", "4", "5", "6", "7", (char *)NULL);
	test_tool_wait();

	TEST_ASSERT(test_tool_exited());
	TEST_ASSERT_RET_OK(test_tool_exit_status());
	TEST_ASSERT_NOT_NULL(test_tool_stdout());
	TEST_ASSERT_NULL(test_tool_stderr());
	TEST_ASSERT_STR_EQ(test_tool_stdout(), "0 0 1 1 0 1 0 1\n");
}
TEST_DEFINE(gpioget_read_all_lines,
	    "tools: gpioget - read all lines",
	    0, { 8, 8, 8 });

static void gpioget_read_all_lines_active_low(void)
{
	unsigned int offsets[4];
	int rv, values[4];

	test_tool_run("gpioget", "--active-low", "gpiochip1",
		      "0", "1", "2", "3", "4", "5", "6", "7", (char *)NULL);
	test_tool_wait();

	TEST_ASSERT(test_tool_exited());
	TEST_ASSERT_RET_OK(test_tool_exit_status());
	TEST_ASSERT_NOT_NULL(test_tool_stdout());
	TEST_ASSERT_NULL(test_tool_stderr());
	TEST_ASSERT_STR_EQ(test_tool_stdout(), "1 1 1 1 1 1 1 1\n");

	offsets[0] = 2;
	offsets[1] = 3;
	offsets[2] = 5;
	offsets[3] = 7;

	values[0] = values[1] = values[2] = values[3] = 1;

	rv = gpiod_simple_set_value_multiple(TEST_CONSUMER, test_chip_name(1),
					     offsets, values, 4, false,
					     NULL, NULL);
	TEST_ASSERT_RET_OK(rv);

	test_tool_run("gpioget", "--active-low", "gpiochip1",
		      "0", "1", "2", "3", "4", "5", "6", "7", (char *)NULL);
	test_tool_wait();

	TEST_ASSERT(test_tool_exited());
	TEST_ASSERT_RET_OK(test_tool_exit_status());
	TEST_ASSERT_NOT_NULL(test_tool_stdout());
	TEST_ASSERT_NULL(test_tool_stderr());
	TEST_ASSERT_STR_EQ(test_tool_stdout(), "1 1 0 0 1 0 1 0\n");
}
TEST_DEFINE(gpioget_read_all_lines_active_low,
	    "tools: gpioget - read all lines (active-low)",
	    0, { 8, 8, 8 });

static void gpioget_read_some_lines(void)
{
	unsigned int offsets[3];
	int rv, values[3];

	test_tool_run("gpioget", "gpiochip1",
		      "0", "1", "4", "6", (char *)NULL);
	test_tool_wait();

	TEST_ASSERT(test_tool_exited());
	TEST_ASSERT_RET_OK(test_tool_exit_status());
	TEST_ASSERT_NOT_NULL(test_tool_stdout());
	TEST_ASSERT_NULL(test_tool_stderr());
	TEST_ASSERT_STR_EQ(test_tool_stdout(), "0 0 0 0\n");

	offsets[0] = 1;
	offsets[1] = 4;
	offsets[2] = 6;

	values[0] = values[1] = values[2] = 1;

	rv = gpiod_simple_set_value_multiple(TEST_CONSUMER, test_chip_name(1),
					     offsets, values, 3, false,
					     NULL, NULL);
	TEST_ASSERT_RET_OK(rv);

	test_tool_run("gpioget", "gpiochip1",
			      "0", "1", "4", "6", (char *)NULL);
	test_tool_wait();

	TEST_ASSERT(test_tool_exited());
	TEST_ASSERT_RET_OK(test_tool_exit_status());
	TEST_ASSERT_NOT_NULL(test_tool_stdout());
	TEST_ASSERT_NULL(test_tool_stderr());
	TEST_ASSERT_STR_EQ(test_tool_stdout(), "0 1 1 1\n");
}
TEST_DEFINE(gpioget_read_some_lines,
	    "tools: gpioget - read some lines",
	    0, { 8, 8, 8 });
{'fraction_non_alphanumeric': 0.1659263130389339, 'fraction_numerical': 0.03971779461719362, 'mean_word_length': 5.119104716227018, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4401900', 'n_tokens_mistral': 3408, 'n_tokens_neox': 3111, 'n_words': 628}