-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds proof harness for aws_byte_buf_write function (#360)
* Adds proof harness for aws_byte_buf_write function
- Loading branch information
1 parent
3f379a8
commit d813977
Showing
7 changed files
with
85 additions
and
3 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 2019 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 ../Makefile.aws_byte_buf | ||
|
||
CBMCFLAGS += | ||
|
||
DEPENDENCIES += $(HELPERDIR)/source/make_common_data_structures.c | ||
DEPENDENCIES += $(HELPERDIR)/source/proof_allocators.c | ||
DEPENDENCIES += $(HELPERDIR)/source/utils.c | ||
DEPENDENCIES += $(HELPERDIR)/stubs/error.c | ||
DEPENDENCIES += $(SRCDIR)/source/byte_buf.c | ||
DEPENDENCIES += $(SRCDIR)/source/common.c | ||
|
||
ENTRY = aws_byte_buf_write_harness | ||
########### | ||
|
||
include ../Makefile.common |
46 changes: 46 additions & 0 deletions
46
.cbmc-batch/jobs/aws_byte_buf_write/aws_byte_buf_write_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,46 @@ | ||
/* | ||
* Copyright 2019 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_write_harness() { | ||
/* parameters */ | ||
struct aws_byte_buf buf; | ||
size_t len; | ||
uint8_t *array = can_fail_malloc(len); | ||
|
||
/* assumptions */ | ||
ensure_byte_buf_has_allocated_buffer_member(&buf); | ||
__CPROVER_assume(aws_byte_buf_is_valid(&buf)); | ||
|
||
/* save current state of the parameters */ | ||
struct aws_byte_buf old = buf; | ||
struct store_byte_from_buffer old_byte_from_buf; | ||
save_byte_from_array(buf.buffer, buf.len, &old_byte_from_buf); | ||
|
||
if (aws_byte_buf_write((nondet_bool() ? &buf : NULL), array, len)) { | ||
assert(buf.len == old.len + len); | ||
assert(old.capacity == buf.capacity); | ||
assert(old.allocator == buf.allocator); | ||
if (len > 0 && buf.len > 0) { | ||
assert_bytes_match(buf.buffer + old.len, array, len); | ||
} | ||
} else { | ||
assert_byte_buf_equivalence(&buf, &old, &old_byte_from_buf); | ||
} | ||
|
||
assert(aws_byte_buf_is_valid(&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;--div-by-zero-check;--float-overflow-check;--nan-check;--pointer-check;--pointer-overflow-check;--signed-overflow-check;--undefined-shift-check;--unsigned-overflow-check;--unwind;1;--unwinding-assertions;--object-bits;8" | ||
goto: aws_byte_buf_write_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