Skip to content

Commit 4e6abf8

Browse files
authored
Make sure size_test CI uses -Wall -Werror (#8016)
1 parent 70143a2 commit 4e6abf8

File tree

7 files changed

+37
-29
lines changed

7 files changed

+37
-29
lines changed

CONTRIBUTING.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,14 @@ must work with threading**
215215

216216
## Testing
217217

218+
### Running Tests Locally
219+
220+
CI is run automatically on all pull requests. However, if you want to run tests locally, here are some example commands (not exhaustive):
221+
222+
- The `sh test/build_size_test.sh` script will compile the C++runtime along with portable kernels.
223+
- The `test/run_oss_cpp_tests.sh` script will build and run C++ tests locally
224+
- Running `pytest` from the root directory will run Python tests locally.
225+
218226
### Writing Tests
219227
To help keep code quality high, ExecuTorch uses a combination of unit tests and
220228
end-to-end (e2e) tests. If you add a new feature or fix a bug, please add tests
@@ -229,8 +237,6 @@ If it's not clear how to add a test for your PR, take a look at the blame for
229237
the code you're modifying and find an author who has more context. Ask them
230238
for their help in the PR comments.
231239

232-
The `test/run_oss_cpp_tests.sh` script will build and run C++ tests locally.
233-
234240
### Continuous Integration
235241
See https://hud.pytorch.org/hud/pytorch/executorch/main for the current state of
236242
the CI (continuous integration) jobs. If `main` is broken, consider rebasing

kernels/portable/cpu/op_full.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ Tensor& full_out(
3838

3939
ET_SWITCH_SCALAR_OBJ_TYPES(val_type, ctx, name, CTYPE_VAL, [&] {
4040
CTYPE_VAL val;
41-
utils::extract_scalar(fill_value, &val);
41+
ET_KERNEL_CHECK(
42+
ctx, utils::extract_scalar(fill_value, &val), InvalidArgument, );
4243

4344
ET_SWITCH_REALHBBF16_TYPES(out_type, ctx, name, CTYPE_OUT, [&] {
4445
CTYPE_OUT val_casted = static_cast<CTYPE_OUT>(val);

kernels/portable/cpu/op_full_like.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ Tensor& full_like_out(
5454

5555
ET_SWITCH_REALB_TYPES(val_type, ctx, name, CTYPE_VAL, [&] {
5656
CTYPE_VAL val;
57-
utils::extract_scalar(fill_value, &val);
57+
ET_KERNEL_CHECK(
58+
ctx, utils::extract_scalar(fill_value, &val), InvalidArgument, );
5859

5960
ET_SWITCH_REALHBBF16_TYPES(out_type, ctx, name, CTYPE_OUT, [&] {
6061
CTYPE_OUT val_casted = static_cast<CTYPE_OUT>(val);

kernels/portable/cpu/op_scatter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ Tensor& scatter_value_out(
156156

157157
ET_SWITCH_SCALAR_OBJ_TYPES(val_type, ctx, name, CTYPE_VAL, [&] {
158158
CTYPE_VAL val;
159-
utils::extract_scalar(value, &val);
159+
ET_KERNEL_CHECK(ctx, utils::extract_scalar(value, &val), InvalidArgument, );
160160

161161
ET_SWITCH_REALHBBF16_TYPES(in.scalar_type(), ctx, name, CTYPE, [&]() {
162162
scatter_value_helper<CTYPE>(in, dim, index, val, out);

kernels/portable/cpu/util/broadcast_util.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -215,18 +215,16 @@ ET_NODISCARD Error get_broadcast_target_size(
215215
size_t* out_dim) {
216216
if ET_UNLIKELY (!tensors_are_broadcastable_between(a_size, b_size)) {
217217
#ifdef ET_LOG_ENABLED
218-
const auto a_shape_str = tensor_shape_to_c_string(
219-
executorch::runtime::Span<const Tensor::SizesType>(
220-
a_size.data(), a_size.size()));
221-
const auto b_shape_str = tensor_shape_to_c_string(
222-
executorch::runtime::Span<const Tensor::SizesType>(
223-
b_size.data(), b_size.size()));
224-
#endif
218+
executorch::runtime::Span<const Tensor::SizesType> a_size_span(
219+
a_size.data(), a_size.size());
220+
executorch::runtime::Span<const Tensor::SizesType> b_size_span(
221+
b_size.data(), b_size.size());
225222
ET_LOG(
226223
Error,
227224
"Two input tensors should be broadcastable but got shapes %s and %s.",
228-
a_shape_str.data(),
229-
b_shape_str.data());
225+
tensor_shape_to_c_string(a_size_span).data(),
226+
tensor_shape_to_c_string(b_size_span).data());
227+
#endif
230228
return executorch::runtime::Error::InvalidArgument;
231229
}
232230

runtime/core/portable_type/tensor_impl.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,18 @@ Error TensorImpl::internal_resize_contiguous(ArrayRef<SizesType> new_sizes) {
9696
case TensorShapeDynamism::STATIC:
9797
if (!std::equal(sizes_, sizes_ + dim_, new_sizes.begin())) {
9898
#ifdef ET_LOG_ENABLED
99-
auto old_sizes_str = executorch::runtime::tensor_shape_to_c_string(
100-
executorch::runtime::Span<const SizesType>(
101-
sizes().data(), sizes().size()));
102-
auto new_sizes_str = executorch::runtime::tensor_shape_to_c_string(
103-
executorch::runtime::Span<const SizesType>(
104-
new_sizes.data(), new_sizes.size()));
105-
#endif
106-
107-
ET_CHECK_OR_RETURN_ERROR(
108-
false,
109-
NotSupported,
99+
executorch::runtime::Span<const SizesType> sizes_span(
100+
sizes().data(), sizes().size());
101+
executorch::runtime::Span<const SizesType> new_sizes_span(
102+
new_sizes.data(), new_sizes.size());
103+
ET_LOG(
104+
Error,
110105
"Attempted to resize a static tensor. Expected shape %s, but received %s.",
111-
old_sizes_str.data(),
112-
new_sizes_str.data())
106+
executorch::runtime::tensor_shape_to_c_string(sizes_span).data(),
107+
executorch::runtime::tensor_shape_to_c_string(new_sizes_span)
108+
.data());
109+
#endif
110+
return executorch::runtime::Error::NotSupported;
113111
}
114112

115113
break;

test/build_size_test.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,15 @@ set -e
1111
# shellcheck source=/dev/null
1212
source "$(dirname "${BASH_SOURCE[0]}")/../.ci/scripts/utils.sh"
1313

14+
# TODO(#8149): Remove -Wno-sign-compare
15+
# TODO(#8357): Remove -Wno-int-in-bool-context
16+
COMMON_CXXFLAGS="-fno-exceptions -fno-rtti -Wall -Werror -Wno-sign-compare -Wno-unknown-pragmas -Wno-int-in-bool-context"
17+
1418
cmake_install_executorch_lib() {
1519
echo "Installing libexecutorch.a"
1620
clean_executorch_install_folders
1721

18-
CXXFLAGS="-fno-exceptions -fno-rtti" retry cmake -DBUCK2="$BUCK2" \
22+
CXXFLAGS="$COMMON_CXXFLAGS" retry cmake -DBUCK2="$BUCK2" \
1923
-DCMAKE_CXX_STANDARD_REQUIRED=ON \
2024
-DCMAKE_INSTALL_PREFIX=cmake-out \
2125
-DCMAKE_BUILD_TYPE=Release \
@@ -27,7 +31,7 @@ cmake_install_executorch_lib() {
2731
}
2832

2933
test_cmake_size_test() {
30-
CXXFLAGS="-fno-exceptions -fno-rtti" retry cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=cmake-out -Bcmake-out/test test
34+
CXXFLAGS="$COMMON_CXXFLAGS" retry cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=cmake-out -Bcmake-out/test test
3135

3236
echo "Build size test"
3337
cmake --build cmake-out/test -j9 --config Release

0 commit comments

Comments
 (0)