forked from solana-labs/solana
-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor - Avoid host build of SBPF program test crates #1711
Merged
Lichtso
merged 9 commits into
anza-xyz:master
from
Lichtso:refactor/avoid_host_build_of_program_test_crates
Jun 18, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
43822ff
Removes ProgramTest from simulation tests.
Lichtso 5a74385
Removes ProgramTest from sysvar syscall tests.
Lichtso 5b39e3c
Workaround for rustc crash caused by 16 byte alined memcpy.
Lichtso b1d26b9
Deduplicates test_program_sbf_sanity.
Lichtso 16951f0
Moves mem and remaining_compute_units into test_program_sbf_sanity().
Lichtso 8e204a3
Removes unused dev-dependencies in Cargo.toml.
Lichtso 295ec36
Removes crate-type = lib from Cargo.tomls.
Lichtso 1662ff1
Adds SBF_OUT_DIR env to CI script.
Lichtso 2d535cb
Adds "sysvar" to build.rs.
Lichtso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -108,6 +108,7 @@ fn main() { | |
"simulation", | ||
"spoof1", | ||
"spoof1_system", | ||
"sysvar", | ||
"upgradeable", | ||
"upgraded", | ||
]; | ||
|
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
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 was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,44 +1,86 @@ | ||
#![cfg(feature = "test-bpf")] | ||
|
||
use { | ||
solana_program_test::{processor, tokio, ProgramTest}, | ||
solana_sbf_rust_simulation::process_instruction, | ||
agave_validator::test_validator::*, | ||
solana_runtime::{ | ||
bank::Bank, | ||
bank_client::BankClient, | ||
genesis_utils::{create_genesis_config, GenesisConfigInfo}, | ||
loader_utils::load_upgradeable_program_and_advance_slot, | ||
}, | ||
solana_sdk::{ | ||
instruction::{AccountMeta, Instruction}, | ||
message::Message, | ||
pubkey::Pubkey, | ||
signature::Signer, | ||
sysvar, | ||
transaction::Transaction, | ||
signature::{Keypair, Signer}, | ||
sysvar::{clock, slot_history}, | ||
transaction::{SanitizedTransaction, Transaction}, | ||
}, | ||
}; | ||
|
||
#[tokio::test] | ||
async fn no_panic_banks_client() { | ||
let program_id = Pubkey::new_unique(); | ||
let program_test = ProgramTest::new( | ||
#[test] | ||
#[cfg(feature = "sbf_rust")] | ||
fn test_no_panic_banks_client() { | ||
solana_logger::setup(); | ||
|
||
let GenesisConfigInfo { | ||
genesis_config, | ||
mint_keypair, | ||
.. | ||
} = create_genesis_config(50); | ||
let (bank, bank_forks) = Bank::new_with_bank_forks_for_tests(&genesis_config); | ||
let mut bank_client = BankClient::new_shared(bank.clone()); | ||
let authority_keypair = Keypair::new(); | ||
let (bank, program_id) = load_upgradeable_program_and_advance_slot( | ||
&mut bank_client, | ||
bank_forks.as_ref(), | ||
&mint_keypair, | ||
&authority_keypair, | ||
"solana_sbf_rust_simulation", | ||
); | ||
bank.freeze(); | ||
|
||
let instruction = Instruction::new_with_bincode( | ||
program_id, | ||
processor!(process_instruction), | ||
&[0u8; 0], | ||
vec![ | ||
AccountMeta::new_readonly(slot_history::id(), false), | ||
AccountMeta::new_readonly(clock::id(), false), | ||
], | ||
); | ||
let blockhash = bank.last_blockhash(); | ||
let message = Message::new(&[instruction], Some(&mint_keypair.pubkey())); | ||
let transaction = Transaction::new(&[&mint_keypair], message, blockhash); | ||
let sanitized_tx = SanitizedTransaction::from_transaction_for_tests(transaction); | ||
let result = bank.simulate_transaction(&sanitized_tx, false); | ||
assert!(result.result.is_ok()); | ||
} | ||
|
||
#[test] | ||
#[cfg(feature = "sbf_rust")] | ||
fn test_no_panic_rpc_client() { | ||
solana_logger::setup(); | ||
|
||
let program_id = Pubkey::new_unique(); | ||
let (test_validator, payer) = TestValidatorGenesis::default() | ||
.add_program("solana_sbf_rust_simulation", program_id) | ||
.start(); | ||
let rpc_client = test_validator.get_rpc_client(); | ||
let blockhash = rpc_client.get_latest_blockhash().unwrap(); | ||
|
||
let mut context = program_test.start_with_context().await; | ||
let transaction = Transaction::new_signed_with_payer( | ||
&[Instruction { | ||
program_id, | ||
accounts: vec![ | ||
AccountMeta::new_readonly(sysvar::slot_history::id(), false), | ||
AccountMeta::new_readonly(sysvar::clock::id(), false), | ||
AccountMeta::new_readonly(slot_history::id(), false), | ||
AccountMeta::new_readonly(clock::id(), false), | ||
], | ||
data: vec![], | ||
}], | ||
Some(&context.payer.pubkey()), | ||
&[&context.payer], | ||
context.last_blockhash, | ||
Some(&payer.pubkey()), | ||
&[&payer], | ||
blockhash, | ||
); | ||
|
||
context | ||
.banks_client | ||
.process_transaction_with_preflight(transaction) | ||
.await | ||
rpc_client | ||
.send_and_confirm_transaction(&transaction) | ||
buffalojoec marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.unwrap(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I'm missing something, but what are these panics supposed to catch that the error doesn't? The test is just making sure the result is
Ok(())
, so unless you're debugging I would assume this is no different than the test failing on the thrown error.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes looks funny I know. All of these
?
=>.unwrap()
changes are in the commit Workaround for rustc crash caused by 16 byte alined memcpy.Lucas is already working on fixing that, but it takes one release cycle of the platform tools, so this is the workaround for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this workaround actually work, though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The memcpy is not explicit it happens because of stack spilling / register pressure as far as I can tell. So pretty much any change to the code can cause it to go either way. With the next release of the platform tools that should be fixed, and until then the behavior is stable.