[test determinator] Add the hash function that we use in the plugin to hash the mangled names to compare input mangled names
Reviewed By: dulmarod Differential Revision: D17602494 fbshipit-source-id: ad704cf19master
parent
b82450d576
commit
25f2293e70
@ -0,0 +1,11 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
#
|
||||||
|
# This source code is licensed under the MIT license found in the
|
||||||
|
# LICENSE file in the root directory of this source tree.
|
||||||
|
|
||||||
|
## Wrapper around the bytecode version of infer produced by `make byte`
|
||||||
|
# This is needed to find the dynamic libraries of our C stubs
|
||||||
|
|
||||||
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
exec "$SCRIPT_DIR"/../../scripts/dune_exec_shim.sh "${0%.byte}.bc" "$@"
|
@ -0,0 +1,8 @@
|
|||||||
|
(*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*)
|
||||||
|
|
||||||
|
external fnv64_hash : string -> string = "fnv64_hash"
|
@ -0,0 +1,18 @@
|
|||||||
|
(* -*- tuareg -*- *)
|
||||||
|
(*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*)
|
||||||
|
|
||||||
|
;;
|
||||||
|
Format.sprintf
|
||||||
|
{|
|
||||||
|
(library
|
||||||
|
(name InferCStubs)
|
||||||
|
(public_name InferCStubs)
|
||||||
|
(c_names fnv64_hash)
|
||||||
|
)
|
||||||
|
|}
|
||||||
|
|> Jbuild_plugin.V1.send
|
@ -0,0 +1,2 @@
|
|||||||
|
(lang dune 1.10)
|
||||||
|
(name CStubs)
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
#include <caml/mlvalues.h>
|
||||||
|
#include <caml/alloc.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
// 64 bits fnv-1a
|
||||||
|
const uint64_t FNV64_hash_start = 14695981039346656037ULL;
|
||||||
|
const uint64_t FNV64_prime = 1099511628211ULL;
|
||||||
|
uint64_t fnv64_hash_impl(const char* s) {
|
||||||
|
uint64_t hash = FNV64_hash_start;
|
||||||
|
while (*s != 0) {
|
||||||
|
hash ^= *s;
|
||||||
|
hash *= FNV64_prime;
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
CAMLprim value fnv64_hash(value c) {
|
||||||
|
char* c_string = String_val(c);
|
||||||
|
uint64_t hashed = fnv64_hash_impl(c_string);
|
||||||
|
char str[21];
|
||||||
|
snprintf(str, 21, "%" PRIu64, hashed);
|
||||||
|
return caml_copy_string(str);
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
(*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*)
|
||||||
|
|
||||||
|
open! IStd
|
||||||
|
open OUnit2
|
||||||
|
|
||||||
|
let pp_diff_of_hashed_value fmt (expected, actual) =
|
||||||
|
Format.fprintf fmt "Expected: [%s] Found: [%s]" expected actual
|
||||||
|
|
||||||
|
|
||||||
|
let test_fnv64_hash_function =
|
||||||
|
let create_test (input : string) (hashed_input : string) _ =
|
||||||
|
let actual_hashed_value = Fnv64Hash.fnv64_hash input in
|
||||||
|
let cmp s1 s2 = String.equal s1 s2 in
|
||||||
|
assert_equal ~pp_diff:pp_diff_of_hashed_value ~cmp hashed_input actual_hashed_value
|
||||||
|
in
|
||||||
|
[("test_correct_hash", "_Z4testv", "18241244337164948030")]
|
||||||
|
|> List.map ~f:(fun (name, test_input, expected_output) ->
|
||||||
|
name >:: create_test test_input expected_output )
|
||||||
|
|
||||||
|
|
||||||
|
let tests = "fnv64_hash_function_suite" >::: test_fnv64_hash_function
|
@ -0,0 +1,25 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
#
|
||||||
|
# This source code is licensed under the MIT license found in the
|
||||||
|
# LICENSE file in the root directory of this source tree.
|
||||||
|
|
||||||
|
## Wrapper around the bytecode versions of infer
|
||||||
|
# This is needed to find the dynamic libraries of our C stubs
|
||||||
|
|
||||||
|
if [ "$#" -lt 1 ]; then
|
||||||
|
echo "usage: $0 BYTECODE_PROGRAM" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
prog=$1
|
||||||
|
shift
|
||||||
|
|
||||||
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
SRC_DIR="$SCRIPT_DIR"/../infer/src
|
||||||
|
BUILD_MODE=${BUILD_MODE:-default}
|
||||||
|
DUNE_INSTALL_DIR=${INSTALL_DIR:-"$SRC_DIR/_build/install/$BUILD_MODE"}
|
||||||
|
|
||||||
|
export CAML_LD_LIBRARY_PATH="$DUNE_INSTALL_DIR"/lib/stublibs:"$CAML_LD_LIBRARY_PATH"
|
||||||
|
|
||||||
|
exec "$prog" "$@"
|
Loading…
Reference in new issue