-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Byte buf utility functions - append that grows, append with internal …
…tolower, reserve (#297) * Byte buf append function that grows when capacity limit hit * Byte buf reserve * Byte buf append with lookup table translation
- Loading branch information
1 parent
a4f2f60
commit 286d802
Showing
19 changed files
with
632 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use | ||
# this file except in compliance with the License. A copy of the License is | ||
# located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "license" file accompanying this file. This file is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
# implied. See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
########### | ||
CBMC_UNWINDSET = | ||
|
||
CBMCFLAGS += | ||
|
||
DEPENDENCIES += $(HELPERDIR)/source/make_common_data_structures.c | ||
DEPENDENCIES += $(HELPERDIR)/source/proof_allocators.c | ||
DEPENDENCIES += $(HELPERDIR)/stubs/error.c | ||
DEPENDENCIES += $(HELPERDIR)/stubs/memcpy_override_no_op.c | ||
DEPENDENCIES += $(SRCDIR)/source/byte_buf.c | ||
DEPENDENCIES += $(SRCDIR)/source/common.c | ||
|
||
ENTRY = aws_byte_buf_append_dynamic_harness | ||
########### | ||
|
||
include ../Makefile.common |
33 changes: 33 additions & 0 deletions
33
.cbmc-batch/jobs/aws_byte_buf_append_dynamic/aws_byte_buf_append_dynamic_harness.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
#include <aws/common/byte_buf.h> | ||
#include <proof_helpers/make_common_data_structures.h> | ||
|
||
void aws_byte_buf_append_dynamic_harness() { | ||
struct aws_byte_buf to; | ||
__CPROVER_assume(aws_byte_buf_is_valid(&to)); | ||
ensure_byte_buf_has_allocated_buffer_member(&to); | ||
|
||
struct aws_byte_cursor from; | ||
__CPROVER_assume(aws_byte_cursor_is_valid(&from)); | ||
ensure_byte_cursor_has_allocated_buffer_member(&from); | ||
|
||
aws_byte_buf_append_dynamic(&to, &from); | ||
|
||
assert(aws_byte_buf_is_valid(&to)); | ||
assert(is_byte_buf_expected_alloc(&to)); | ||
assert(aws_byte_cursor_is_valid(&from)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
jobos: ubuntu16 | ||
cbmcflags: "--bounds-check;--pointer-check;--div-by-zero-check;--signed-overflow-check;--unsigned-overflow-check;--pointer-overflow-check;--undefined-shift-check;--float-overflow-check;--nan-check;--unwinding-assertions;--function;aws_byte_buf_append_dynamic_harness" | ||
goto: aws_byte_buf_append_dynamic_harness.goto | ||
expected: "SUCCESSFUL" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use | ||
# this file except in compliance with the License. A copy of the License is | ||
# located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "license" file accompanying this file. This file is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
# implied. See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
########### | ||
# This size is suficcient to get full code coverage | ||
MAX_BUF_SIZE ?= 10 | ||
DEFINES += -DMAX_BUF_SIZE=$(MAX_BUF_SIZE) | ||
|
||
#A hash entry is 24 bytes, which is 3 iters. So we need 3 * MAX_TABLE_SIZE + 1 | ||
UNWINDSET += aws_byte_buf_append_with_lookup.0:$(shell echo $$(($(MAX_BUF_SIZE) + 1))) | ||
|
||
CBMCFLAGS += | ||
|
||
DEPENDENCIES += $(HELPERDIR)/source/make_common_data_structures.c | ||
DEPENDENCIES += $(HELPERDIR)/source/proof_allocators.c | ||
DEPENDENCIES += $(HELPERDIR)/stubs/error.c | ||
DEPENDENCIES += $(HELPERDIR)/stubs/memcpy_override_no_op.c | ||
DEPENDENCIES += $(SRCDIR)/source/byte_buf.c | ||
DEPENDENCIES += $(SRCDIR)/source/common.c | ||
|
||
ENTRY = aws_byte_buf_append_with_lookup_harness | ||
########### | ||
|
||
include ../Makefile.common |
40 changes: 40 additions & 0 deletions
40
.cbmc-batch/jobs/aws_byte_buf_append_with_lookup/aws_byte_buf_append_with_lookup_harness.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
#include <aws/common/byte_buf.h> | ||
#include <proof_helpers/make_common_data_structures.h> | ||
|
||
void aws_byte_buf_append_with_lookup_harness() { | ||
struct aws_byte_buf to; | ||
__CPROVER_assume(is_bounded_byte_buf(&to, MAX_BUF_SIZE)); | ||
__CPROVER_assume(aws_byte_buf_is_valid(&to)); | ||
ensure_byte_buf_has_allocated_buffer_member(&to); | ||
|
||
struct aws_byte_cursor from; | ||
__CPROVER_assume(is_bounded_byte_cursor(&from, MAX_BUF_SIZE)); | ||
__CPROVER_assume(aws_byte_cursor_is_valid(&from)); | ||
ensure_byte_cursor_has_allocated_buffer_member(&from); | ||
|
||
/** | ||
* The specification for the function requires that the buffer | ||
* be at least 256 bytes. | ||
*/ | ||
uint8_t *lookup_table[256]; | ||
aws_byte_buf_append_with_lookup(&to, &from, lookup_table); | ||
|
||
assert(aws_byte_buf_is_valid(&to)); | ||
assert(is_byte_buf_expected_alloc(&to)); | ||
assert(aws_byte_cursor_is_valid(&from)); | ||
} |
4 changes: 4 additions & 0 deletions
4
.cbmc-batch/jobs/aws_byte_buf_append_with_lookup/cbmc-batch.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
jobos: ubuntu16 | ||
cbmcflags: "--bounds-check;--pointer-check;--div-by-zero-check;--signed-overflow-check;--unsigned-overflow-check;--pointer-overflow-check;--undefined-shift-check;--float-overflow-check;--nan-check;--unwinding-assertions;--unwindset;aws_byte_buf_append_with_lookup.0:11;--function;aws_byte_buf_append_with_lookup_harness" | ||
goto: aws_byte_buf_append_with_lookup_harness.goto | ||
expected: "SUCCESSFUL" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use | ||
# this file except in compliance with the License. A copy of the License is | ||
# located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "license" file accompanying this file. This file is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
# implied. See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
########### | ||
CBMC_UNWINDSET = | ||
|
||
CBMCFLAGS += | ||
|
||
DEPENDENCIES += $(HELPERDIR)/source/make_common_data_structures.c | ||
DEPENDENCIES += $(HELPERDIR)/source/proof_allocators.c | ||
DEPENDENCIES += $(HELPERDIR)/stubs/error.c | ||
DEPENDENCIES += $(HELPERDIR)/stubs/memcpy_override_no_op.c | ||
DEPENDENCIES += $(SRCDIR)/source/byte_buf.c | ||
DEPENDENCIES += $(SRCDIR)/source/common.c | ||
|
||
ENTRY = aws_byte_buf_reserve_harness | ||
########### | ||
|
||
include ../Makefile.common |
33 changes: 33 additions & 0 deletions
33
.cbmc-batch/jobs/aws_byte_buf_reserve/aws_byte_buf_reserve_harness.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
#include <aws/common/byte_buf.h> | ||
#include <proof_helpers/make_common_data_structures.h> | ||
|
||
void aws_byte_buf_reserve_harness() { | ||
struct aws_byte_buf buf; | ||
__CPROVER_assume(aws_byte_buf_is_valid(&buf)); | ||
ensure_byte_buf_has_allocated_buffer_member(&buf); | ||
|
||
struct aws_byte_buf old = buf; | ||
size_t requested_capacity; | ||
int rval = aws_byte_buf_reserve(&buf, requested_capacity); | ||
|
||
if (rval == AWS_OP_SUCCESS) { | ||
assert(buf.capacity >= requested_capacity); | ||
} | ||
assert(aws_byte_buf_is_valid(&buf)); | ||
assert(is_byte_buf_expected_alloc(&buf)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
jobos: ubuntu16 | ||
cbmcflags: "--bounds-check;--pointer-check;--div-by-zero-check;--signed-overflow-check;--unsigned-overflow-check;--pointer-overflow-check;--undefined-shift-check;--float-overflow-check;--nan-check;--unwinding-assertions;--function;aws_byte_buf_reserve_harness" | ||
goto: aws_byte_buf_reserve_harness.goto | ||
expected: "SUCCESSFUL" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.