|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | +/* |
| 3 | +Copyright (C) 2024 The Falco Authors. |
| 4 | +
|
| 5 | +Licensed under the Apache License, Version 2.0 (the "License")); |
| 6 | +you may not use this file except in compliance with the License. |
| 7 | +You may obtain a copy of the License at |
| 8 | +
|
| 9 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +
|
| 11 | +Unless required by applicable law or agreed to in writing, software |
| 12 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +See the License for the specific language governing permissions and |
| 15 | +limitations under the License. |
| 16 | +
|
| 17 | +*/ |
| 18 | + |
| 19 | +#include <libsinsp/sinsp.h> |
| 20 | +#include <gtest/gtest.h> |
| 21 | + |
| 22 | +#include <sinsp_with_test_input.h> |
| 23 | + |
| 24 | +TEST_F(sinsp_with_test_input, signed_int_compare) |
| 25 | +{ |
| 26 | + add_default_init_thread(); |
| 27 | + |
| 28 | + open_inspector(); |
| 29 | + |
| 30 | + sinsp_evt * evt = add_event_advance_ts(increasing_ts(), 1, PPME_SYSCALL_EPOLL_CREATE_X, 1, (uint64_t)-22); |
| 31 | + |
| 32 | + EXPECT_EQ(get_field_as_string(evt, "evt.cpu"), "1"); |
| 33 | + |
| 34 | + EXPECT_TRUE(eval_filter(evt, "evt.cpu < 300")); |
| 35 | + EXPECT_FALSE(eval_filter(evt, "evt.cpu > 300")); |
| 36 | + EXPECT_TRUE(eval_filter(evt, "evt.cpu < 2")); |
| 37 | + EXPECT_TRUE(eval_filter(evt, "evt.cpu > -500")); |
| 38 | + EXPECT_TRUE(eval_filter(evt, "evt.cpu < 500")); |
| 39 | + EXPECT_TRUE(eval_filter(evt, "evt.cpu <= 500")); |
| 40 | + |
| 41 | + EXPECT_TRUE(eval_filter(evt, "evt.cpu <= 1025")); |
| 42 | + EXPECT_FALSE(eval_filter(evt, "evt.cpu >= 1025")); |
| 43 | + |
| 44 | + EXPECT_FALSE(eval_filter(evt, "evt.rawarg.res > 0")); |
| 45 | + EXPECT_TRUE(eval_filter(evt, "evt.rawarg.res < 0")); |
| 46 | + EXPECT_FALSE(eval_filter(evt, "evt.rawarg.res > 4294967295")); |
| 47 | + EXPECT_TRUE(eval_filter(evt, "evt.rawarg.res < -1")); |
| 48 | + EXPECT_TRUE(eval_filter(evt, "evt.rawarg.res > -65535")); |
| 49 | + |
| 50 | + evt = add_event_advance_ts(increasing_ts(), 1, PPME_SYSCALL_OPEN_E, 3, "/tmp/the_file", PPM_O_NONE, 0666); |
| 51 | + evt = add_event_advance_ts(increasing_ts(), 1, PPME_SYSCALL_OPEN_X, 6, (int64_t)(-1), "/tmp/the_file", PPM_O_NONE, 0666, 123, (uint64_t)456); |
| 52 | + |
| 53 | + EXPECT_FALSE(eval_filter(evt, "fd.num >= 0")); |
| 54 | + EXPECT_FALSE(eval_filter(evt, "fd.num > 0")); |
| 55 | + EXPECT_TRUE(eval_filter(evt, "fd.num < 0")); |
| 56 | + EXPECT_FALSE(eval_filter(evt, "fd.num > 4294967295")); |
| 57 | + EXPECT_FALSE(eval_filter(evt, "fd.num < -1")); |
| 58 | + EXPECT_TRUE(eval_filter(evt, "fd.num > -65535")); |
| 59 | +} |
0 commit comments